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

Shalin Gadhavi
Shalin Gadhavi
513 Points

.format and strings are confusing

Can u help me with this

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

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

First, you need to call the join() method on the string ", " and pass the sundaes list to it. Assign the result to a new variable. Then call the format() method on menu and pass the new string variable to it and assign the result back to menu:

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