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

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Stuck again

menu="Our favourite flavours are:()".format

Honestly don't know what I'm doing

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes=available.split(";")
menu="Our favourite flavours are:()".format

4 Answers

Josh Keenan
Josh Keenan
20,315 Points

Hey, I'll do my best to explain this to you as I think you posted about this before. If you have any questions ask them and if I can't help I know someone who can!

Here's your solution so far.

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes=available.split(";")
menu="Our favourite flavours are:()".format          # <-- ()

Here's my solution to the challenge, I'm gonna go through it step by step.

available = "banana split;hot fudge;cherry;malted;black and white"

sundaes = available.split(';')

menu = "Our available flavors are: {}"

menu = menu.format(", ".join(sundaes))

Firstly, the bit I commented on in your code, the brackets on that line are the wrong type of brackets in this scenario, we use the curly braces , {}, when formatting with strings.

When it comes to using .format(), you need to have the braces within the string at the position you want to slot in whatever it may be, in this case the sundaes all joined together, so lets join the sundaes.

', '.join(sundaes)

When using .join() you choose how you want to join whatever you are joining first, so we want a comma and a space so that is the first part of the statement, then in the brackets we choose the subject of the statement, which is the variable sundaes.

Using .format() is what I'll focus on now. With .format() you want a string (the .join() makes us a string from a list) to be able to use it. So we join the sundaes together, this could have been done in a variable but I prefer doing it in the .format() as it saves a bit of typing.

.format() looks for the curly braces within the string and then replaces them with whatever is in the brackets on .format(), so in this case that is the joined version of sundaes.

Then I save the formatted version of the menu under the same name, menu, to update it.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Two parts are missing: creating a string from the sundae list, and passing string into format. Your menu string had some typos to clean up.

available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(";")
# Make a string from the sundaes
string = ", ".join(sundaes)
# Correct your menu string to match the Task:
#   'available' instead of 'favorite', and 'flavor' (US) instead of 'flavour' (UK) 
#   use format field curly braces {} instead of parens ()
#   add missing period at end of string
# Then use string as argument to format
menu = "Our available flavors are: {}.".format(string)
Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Jamie.

I presume you are stuck at task 2/3 of this code challenge. I see a couple of things you probably need to take care of. You do not need to use the format method (for now, it will be required for task 3/3). Also the menu string does not match the one in the instructions of the code challenge, please review it carefully and you should be good to move on

Vitto

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Thanks again Josh. I really appreciate your time. I'll keep trying. Cheers .Jamie