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

Eliel Afari-Brown
PLUS
Eliel Afari-Brown
Courses Plus Student 199 Points

I dont understand how to do the last question in for the join and split assignment

So for the last question for join and split objective it ask me to join the sundaes list while creating a new variable and for then adjust the menu variable so that the display_menu string is in the format placeholder instead of the previous sundaes one

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

3 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Eliel,

You're SO CLOSE. The problem is that you're not using join() correctly. It's a little confusing because the instructions happen to put the ", " in parentheses just because they were an aside, but string joining works differently than in other languages. You just have to flip things around. It works like this:

'use this string to'.join(this_list_together)

So for this example:

', '.join(sundaes)

Cheers :beers:

-Greg

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

Another thing I'd add on, is that you seem to be formatting the menu variable twice, once with the sundaes and the next with the display_menu. Since we're adding the sundaes inside of the display_menu, we can omit the first menu variable on line 3.

Diego Angarita
Diego Angarita
2,806 Points

I am having the same problem. I have spent hours on this question. I even checked my answer in the console and it seems to work fine. What am I getting wrong?

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

When I do print(display_menu) I get Our available flavors are: banana split, hot fudge, cherry, malted, black and white.

What am I doing wrong?

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Diego - split() takes an argument for what character to split on. If you leave it blank, it defaults to space. That's not what you want; you'll end up with sundaes equal to this list:

['banana', 'split;hot', 'fudge;cherry;malted;black', 'and', 'white']

Make sure you pass split() the ";" character.

Also, I did not realize you could use format that way (on a variable that holds a string with brackets). It totally works, though! Thanks for teaching me something.

Diego Angarita
Diego Angarita
2,806 Points

Yea, I realized that I forgot that part when I was retyping everything from the console. The strange thing is that (with the correction) it works in the console but won't let me move past the quiz.

Greg Kaleka
Greg Kaleka
39,021 Points

OK I looked at the challenge, and the problem is you're not quite following the instructions. Give them another close read and make sure the "answer" is being assigned to the correct variable.

Always a good idea, if it seems like your code is "working" but you're not passing, to make sure you're actually doing what the challenge wants. Code that does what you think it should doesn't necessarily mean it's doing what the challenge is asking for.