Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
19,437 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
19,437 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
19,437 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