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

Python basics, Use split and join. (Need help)

I cant figure out the last step of this assignment, i would love to see the solution, and possibly an explanation, if anyone has the time?

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

4 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You are very close, but it seems like you're not using .format() correctly + you made a typo in your -join() (should be .join())

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
display_menu = ', '.join(sundaes)  # Here you join the list 'sundaes' into a string
menu = 'Our available flavors are: {}.'.format(display_menu)  # Here you format the string using the 'display_menu'

You could also do the format() and join() in one step like this:

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

I hope this makes more sense? :-)

Yea that was a perfect explanation. Now i can finally procced haha! Ty so much for taking the time ;D

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

I would recommend watching the previous video(s) again, but join() is used like this (this confuses a lot of people):

" ".join(some_list_here)  # could also be ", ".join(some_list_here) if you want to join the items with comma :-)

Also, the variable you are using in .format() should be the string you get after joining the list.

I hope this is somewhat helpful :-)

Matthew Price
Matthew Price
511 Points

this one confused me as well. I struggled with it for an hour or so. I would really recommend you try the "brave" method. It's a more concise way of writing it. but yes Henrik is right with the [", ".join(list)] instead of [list.join(", ")].

I'm primarily writing this to tell you to take heart, and don't think you're no good. I thought I was stupid after this question haha.

I still dont understand this assignment my new code look like this: available = "banana split;hot fudge;cherry;malted;black and white" sundaes = available.split(";") menu = "Our available flavors are: {}.".format(sundaes) display_menu = ", "-join("sundaes") But now it says: Oops it looks like task 1 is no longer passing.