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

Ammy Abbott
Ammy Abbott
439 Points

How do I do task 3 of 3? Does Teamtreehouse not provide the correct code if you can't do it?

How do I do task 3 of 3? Does Teamtreehouse not provide the correct code if you can't do it?

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

1 Answer

andren
andren
28,558 Points

Nope, sadly they don't. If you want to know the answer to something your best best is to either ask here or to just google the name of the challenge. That will usually lead you to an older thread on here where somebody has asked for help and has received the answer to the challenge.

Anyway as for the solution, there are two accepted answers. A normal long answer and a "bonus" shortened answer that is more complex. The standard answer is this:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = "Our available flavors are: {}."
# This makes it so display_menu is equal to a string with all of the items of sundaes joined together by the string ", "
# In other words it's equal to: "banana split, hot fudge, cherry, malted, black and white"
display_menu = ", ".join(sundaes) 
# This replaces the menu with one which is formatted using the contents of display_menu
menu = menu.format(display_menu)

I also added comments above the two new lines to clarify them a bit.

Here is the shortened answer if you are curious about that as well:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
# This combines all of the three previous steps into one line
# It does the same thing as the previous example it just skips creating a variable for the joined sundaes
menu = "Our available flavors are: {}.".format(", ".join(sundaes))
Ammy Abbott
Ammy Abbott
439 Points

Awesome, that makes sense now. I've tried another example using the format you gave and it all worked :) Thanks for the lines of explanation too, really helped!

Can you please give andren a "Best Answer" so that this looks like it's already answered in the Community? Thx.

~Alex

William Li (by the way sorry for mentioning you so much William Li)