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

Ian perry
Ian perry
2,674 Points

python super lost on challenge split() join()?

Just can't seem to get my head round the code for task3 ? Any help explaining it would be great. Thanks :)

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

sundaes = available.split(';')

menu = "our available flavors are: {}."

1 Answer

Nathan Tallack
Nathan Tallack
22,160 Points

You have done great. This is what they are looking for in the last step.

menu = menu.format(", ".join(sundaes))

What we are doing here is we are reassigning the menu value to be a new value. The new value is the exisitng vlaue modified with the string format method. That method will get your {}'s out of your string and replace it with the paramaeter you pass in. The parameter we pass in will be a string literal with a join method. The string literal in this case is ", " which is the "seperator" we will use when we call the join method. The join method takes your sundaes list in as a parameter. So the result will be a string which is all the values in that list seperated with the comman and space, and that will all be placed at the end of your menu string. :)

Ian perry
Ian perry
2,674 Points

Hey Nathan Thanks for your help I have gone over the video loads of times and after stepping back and reading what you have put I feel I have a better understanding of .format() & .join() method. Need to keep practising tho Thank you again It was a great help. :)