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

i need help on this question

i don't know how to do this question

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

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

Hey!

Recall that .join is tricky and kind of "backward" from how you might expect it to be used.

If you want to join the list sundaes with the string ", ", you need to actually call the join method on the string and not the list. You're essentially asking the string to join the list, rather than asking the list to join its members with a string.

Like, "Hey comma and space, join up this list for me."

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

You don't have to combine all that in one expression, either. You could join up the sundaes list, store it in a variable, then plug the variable into the format() method if you'd like.