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

Max Wang
Max Wang
287 Points

Replacing Placeholders

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.

I'm very confused about this question. Please help, I would love to solve it.

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

2 Answers

Christian Mangeng
Christian Mangeng
15,970 Points

Hi Max,

the question asks you to do two things. After task 2 your code looks like this:

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

1) Now you should use the join() method to get the items of the "sundaes" list as single string elements and separate each of these elements by a comma and a space. You store that in the variable "display_menu":

display_menu = ", ".join(sundaes)

2) Then you format the placeholder of "menu" (the brackets {}) with display_menu and reassign that back to "menu":

menu = menu.format(display_menu)
Max Wang
Max Wang
287 Points

Thank you very much Christian, that really help out a lot!

hi christian, im having problem with the code, i wrote the above code and it's doesn't work at all at my challenge session, there's always a bummer

Christian Mangeng
Christian Mangeng
15,970 Points

Hi khamarul,

check again. It should work. You need each of the lines of my answer, except for the first one, which is already given in the challenge. Also, check that there is no spacing at the beginning of each line and that you have the lines in the correct order. menu = menu.format(display_menu) needs to be at the end of the code.

hi christian, thank you, i just missed the space after the comma in the quote marks at display_menu, thanks a lot, it is really helps me out

Kent ร…svang
Kent ร…svang
18,823 Points

You should actually use the join-method for this exercise, like so:

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