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
Kelsey West
287 PointsPython use split and join https://teamtreehouse.com/library/python-basics/python-data-types/use-split-and-join
Question: Alright, let's finish making our menu. Using whatever variable name you want (other than sundaes), combine the sundaes list into a new string, joining them with a comma and a space (", "). Use that string with a .format() on our existing menu variable and replace the current value of menu. I got the first two challenges but I can't seem to understand what to put for the third.
3 Answers
Gerald Wells
12,763 PointsQuestion:
Using whatever variable name you want (other than sundaes), combine the sundaes list into a new string, joining them with a comma and a space (", ").
Use that string with a .format() on our existing menu variable and replace the current value of menu.
==============================================================================================
So I think your confusion came from the procedural approach to the question, what helps me solve problems is to look at the larger picture. I know that I need to combine my list with a ", " delimiter, which will give me a string. I am then going to use that value and format menu.
One of the reasons why Python is so powerful is "High order functions"
High Order Functions
Python functions are first-class data objects. This means you can assign them to variables, save them in data structures, pass them as arguments to other functions and return them as values of other functions. A high order function is a function that receives another function as an argument and returns it in some way.
.format() is a high order function, meaning you can pass another function like ''.join() inside it and it will preform that function and then apply it to the larger picture.
Treehouse challenges
Normally you don't have to build your code modularly like the questions state, they are stated they way the are so you understand what needs to be accomplished. Think of the questions as guidelines with required content.
Below I have wrote out the solution, I hope this helps!
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
menu = "Our available flavors are: {}.".format(', '.join(sundaes))
I don't think the challenge will pass with this solution because step 1 required a variable named sundaes, but just to show off more of the power of python you could get rid of the sundaes variable all together, because like .format() ''.join() is a high order function.
available = "banana split;hot fudge;cherry;malted;black and white"
menu = "Our available flavors are: {}.".format(', '.join(available.split(";")))
Alexander Kobilinsky
359 PointsKelsey West
287 PointsThanks so much for you help, yes that was a confusing question on many levels, and when I tried to insert what the video showed it said that it was wrong. I haven't learned .format yet, and it was a little wierd for me to start of with parenthesis instead of a title such as join .