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 do not understand the final step of this code challenge and I need a step by step breakdown of what to do.

I can get through the first two steps but the third continues to elude me.

please help.

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

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points
For the last step we need 2 things. First we need to display the string the challenge wants about "Our flavors..." Second we want to display sundaes with the first part. Like this:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are:{}.".format(", ".join(sundaes))
Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Remember that we use the curly braces in a string as a placeholder. Then we use the .format method to insert the value of a variable inside those curly braces. In this case, it will be a long list of ice cream sundaes! :smiley:

So inside our .format method we want to get the result of the joining of the sundaes list so that it's formatted with a comma and space between each item. So the last piece of code can be written all on one line.

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

This will take our menu string and then place the result of the joining of the sundaes string with a comma and space in between them in the place where the curly braces are.

Hope this helps! :sparkles: