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

Split and Join Excercise

I need help with this exercise. I am stumped as to what the mistake is

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

2 Answers

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

Here's my solution, a lot of people get stuck on this so don't worry, you have to call .join() on a string and give it the thing you want to manipulate as a parameter, so this is how you do it!

display_menu = (", ").join(menu)

is wrong. You don't need display_menu variable because you have value for menu variable in one row. But if you use display_menu, then you have:

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

You can do it in one line yes, but when someone is learning it is better that they see it more clearly and understand everything first, before going to the best solutions. Also my code passes fine it doesn't have to be as you have it

Your code passes fine because only menu variable is checked. What's value of your display_menu variable?

Josh Keenan
Josh Keenan
20,315 Points

oh yeah my bad I didn't realise I did it in one line xD, did it automatically and then did the other bit for the asker