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 trialjohn larson
16,594 PointsSeemed like a bit of a merry go round here...
"available " is a string that is converted to a list "sundaes", that is converted back to a string "string". Was this done just to change the ";" to ","? Is there a more straight forward way to do this?
# string
available = "banana split;hot fudge;cherry;malted;black and white"
# string to a list
sundaes = available.split(";")
# new string with an empty var
menu = "Our available flavors are: {}."
# back to a list
string = ', '.join(sundaes)
# string of available flavors goes into the menu var
menu = menu.format(string)
3 Answers
Jennifer Nordell
Treehouse TeacherHi there john larson. As you suspected there is a slightly more direct way this can be accomplished. But I think the idea here is to make sure that you can do this so that you're set up to work with things like CSV files later down the road. I could be wrong, but it's the theory I have regarding this particular challenge.
I whipped up this code that will do the same thing, but in a little more direct way as you put it.
available = "banana split;hot fudge;cherry;malted;black and white"
menu = "Our available flavors are: {}.".format(available.replace(";", ", "))
print(menu)
edited for additional code Woops forgot the first part of the menu string! Sorry.
Hope this helps!
Chancellor Griffin
2,212 PointsHey, I recently had trouble with this challenge as well because I think the promt is a tad confusing. after task 2 I think it asks you to make that menu variable again and join it, like your line looks like here:
# back to a list
string = ', '.join(sundaes)
this can actually just be put at the end of the line. I had the same problem in my lab
# the menu variable should look like:
menu = "Our available flavors are: {}.".format(", ".join(sundaes))
and also, like I was saying before, the extra menu variable isn't needed, although the promt did mention it.
menu = menu.format(string) # not needed
So you can format using join!
Liam Cassidy
9,739 PointsFor anyone who had the same logic but is still failing:
I noticed that if you put the ", " string in a separate variable (e.g. separator = ", ") you will fail. You have to format it like John Larson did to pass:
string = ', '.join(sundaes)
john larson
16,594 PointsThat's kinda cool...I never thought about putting something like a separator in a variable, thanks