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()

Jt Miller
Jt Miller
1,242 Points

Banana split

Alright, let's finish making our menu. Combine the sundaes list into a new variable named display_menu, where each item in the list is rejoined together by a comma and a space (", "). Then reassign the menu variable to use the existing variable and .format() to replace the placeholder with the new string in display_menu. If you're really brave, you can even accomplish this all on the same line where menu is currently being set.

Is what it is telling me to do and I've tried for the past 15 mins while also using external sites to look for information but still haven't worked it out.

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

1 Answer

Let's take a look at your code:

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

I see you might have trouble with the join method for strings, so here's a little recap.

Join is syntactically different than split in that it takes the joiner first then method call (.join) and in the argument, you put in a list you want to join. For example:

", ".join(some_list)

Another thing I see is that the += operator, while it works on strings, appends to a string. Here, sundaes is a list of available items (['banana split', 'hot fudge', 'cherry', 'malted', 'black and white']) ", ".join(some_list) creates a single string derived from the list of things joined by your joiner. for example

>>>", ".join(sundaes)
'banana split, hot fudge, cherry, malted, black and white'

so, what you want to do is join the list sundaes with the string ", " to make what we have above, and then assign that (not append) to the display_menu variable like such:

display_menu = ", ".join(sundaes)

The last thing you're missing is that if you read the question carefully, it asks you to reassign the menu variable, meaning you have to reassign the menu after you used .format() on it.

menu = menu.format(display_menu)

I hope that helps!

Jt Miller
Jt Miller
1,242 Points

It does help thank you i seem to struggle on .format and .join