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

using .format() with list

I have this task which i could not do. I know that if I want to use .format() I should use string inside the (). I can't figure out what is wrong with it. can you help me figure it out.

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

1 Answer

Thomas Fildes
Thomas Fildes
22,687 Points

Hi Sabaa,

Please see the below code I used to pass this challenge:

available = "banana split;hot fudge;cherry;malted;black and white"

sundaes = available.split(";")

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

The challenge says you can do this in one line of code where menu is set which I have done here.

Basically this code will join the sundaes list together with the .join method (with a comma and space separating each sundae) and then use the result of that to replace the placeholders using .format.

Hope this helps! Happy Coding!!!