Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Python Data Types Use .split() and .join()

Trouble answering Question 1 of Code Challenge.

The Code Challenge Question is ; "I think it's time for a snack. Luckily I have a string full of types of ice cream sundaes. Unluckily, they're all in one string and the string has semi-colons in it too. Use .split() to break the available string apart on the semi-colons (;). Assign this to a new variable sundaes." I simply don't know what next step to take. Here is the code I came up with. I am obviously missing something obvious, but cannot seem to see it.

available = "banana split;hot fudge;cherry;malted;black and white"
available.split(';')
available.join + ';'.join(sundaes)
banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
available.split(';')
available.join + ';'.join(sundaes)

5 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

In task one you only have to "Use .split() to break the available string apart on the semi-colons (;). Assign this to a new variable sundaes.". You could do that like this:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

Remember not to forget the "=" operator to actually assign the String to the "menu" variable.

In the second task you have to create the "menu" variable and assign it the string "Our available flavors are:{}."

Then in the third task you have to format that string, placing in the "placeholder {}" the joined version of the variable "sundaes". Remember that we split the variable "sundaes" so we convert it into a list and then we are converting it to a string again. You could do it like this:

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

Ok, so the second task only passed once I copied Carlos's entire code into it. Adding the "=" operator did nothing. Also, that piece of code solved the second and third task in a row, requiring no additional coding. Why would it do that?

On a side question, for what purpose are the operators {} .". inserted in to the menu value? What purpose do they serve, since we didn't even use the curly braces as a placeholder when we ran ".format" to fill the menu with the "sundaes" variable?

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

Adding the "=" operator didn't make pass the task because you have a dot at the end of the line. So

Task 1:

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")

Task 2:

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

Task 3:

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

You use the "{}" to put in there the string "banana split, hot fudge, cherry, malted, black and white". The one you had in the first place but with commas instead of ";".

Thanks for the help Carlos!

Predictably, I'm not understanding how to solve the next question either.

Let's add a new string variable for displaying our menu items. Make a new variable named menu that's set to "Our available flavors are: {}.".

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

Am I supposed to insert the value of the variable "available" into the wacka wackas?

I'm pretty sure the only thing you are missing here is the = after the word 'menu'.

Remember, anything not assigned to a variable won't be saved and accessible later on (which was your problem with the first part, as you did not assign the .split() to a variable). The = symbol is what tells python 'this is a variable and this is what it holds' so without it python thinks its just broken coding.

Hope this helps! Good luck!

Gotcha. I was confused by the grammar that Treehouse used to write the instructions. They put a period at the end of the sentence, to finish the sentence grammatically. I thought that the period was a piece of syntax,