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 trialtaylor bostic
589 Pointswhat is wrong with is code?
available = "banana split;hot fudge;cherry;malted;black and white" sundaes = available.split(";") menu = "Our available flavors are: {}." display_menu = sundaes.join(",") "Our avaialable flavors: {}.".format("display_menu")
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}."
display_menu = sundaes.join(",")
"Our avaialable flavors: {}.".format("display_menu")
1 Answer
Krishna Pratap Chouhan
15,203 PointsIt is important to remember that "list" object has no attribute or function called 'join'. Join works on strings.
Output of "join" is a string.
what join does is, it takes an argument and insert a string between its each first-level iterative entity. Lets see some example to make sense of it.
list1 = ['a', 'b', 'c']
list2= ["xxxx", "yyy", "zz", "a"]
string1 = "TYU"
string2 = "123"
#now lets see join coming into picture
list1.join(string1)
#It will give error
string1.join(list1)
#it will work fine and the output will be: aTYUbTYUcTYUd
#can you guess the output of:
string1.join(string2)
#the output will be: 1TYU2TYU3
#But since string is also iterable(as seen in string1.join()string2 ) so what you think is the output of
string2.join(list2);
#run it in a workspace and you will see the meaning "first-level iterative entity" in last sentence
#the output will be: xxxx123yyy123zz123a and NOT x123x123x123x123y123y123y123z123z123a
so there was the one mistake you were doing. Second is,
.format(display_menu)
#its should not be in ""
so finally
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = "Our available flavors are: {}."
display_menu = ", ".join(sundaes)
menu = menu.format(display_menu)
Hope this helped.
Dean Meyer
1,378 PointsGreat explanation! Thank you very much!
taylor bostic
589 Pointstaylor bostic
589 Pointskeeps saying Oops! It looks like Task 1 is no longer passing.