Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Use .split() and .join()

Python basics? Bryce Linch

Not sure what 4th line is asking me to do? I understand I'm supposed to create a new variable and join in sundaes using ", " but the 4th line isn't making sense? Where does the {} go for the .format?

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = "Our available flavors are: {}.".format(sundaes)
menulist = sundaes.join(", ")

2 Answers

Idan Melamed
Idan Melamed
16,285 Points

Hi Bryce,

You are very close, and the syntax of creating a string from a list is not very intuitive.

Lets go through this step by step.

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')

Right now sundaes is a list: ['banana split', 'hot fudge', 'cherry', 'malted', 'black and white']

To complete the 3rd challenge we need to turn that list into a string with each item separated by ', ', and assign it to a new variable. After we do that, we should put the new variable in the format().

The syntax of turning ['banana split', 'hot fudge', 'cherry', 'malted', 'black and white'] to 'banana split, hot fudge, cherry, malted, black and white' is:

', '.join(sundaes)

So the rest of the challenge should be:

flavors = ', '.join(sundaes)
menu = "Our available flavors are: {}.".format(flavors)

Hope this helps, Idan

Rustam Ismailov
Rustam Ismailov
6,234 Points

Hi Idan,

Thank you for very detailed and explanatory answer.

I think it is also worth mentioning that we have to put a line which create a new "flavors" string before the: menu = "Our available flavors are: {}.".format(flavors) otherwise the last will not be executed.

Thank you so much! Yeah the wording on this was very confusing, that's why I got tripped up! Thank you!