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

Andrew Zdunek
Andrew Zdunek
432 Points

Trying to figure this problem out - Use .split() to break the available string. Assign new variable - sundaes.

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

This is what I have so far but I have tried other solutions. Topic of the section is Splitting and Joining strings.

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

10 Answers

Gregorio Bernabel
Gregorio Bernabel
3,412 Points

I would say your close its giving you a try again, here all we need to do is just assign the variable available to sundaes and then .split(";") on available.

the way it would work is by doing:

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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I wish I knew what other solutions you tried. But first, the very first line of the challenge should remain unaltered. We're assigning that string into available and now we want to split the string at the semicolons. You have provided a split, but done so on the incorrect line. Also, because your split contains no arguments, it will split on all whitespace instead of the semicolons. Here was my second line:

sundaes = available.split(";")

This takes the string inside the available variable and splits it at the semicolon. The resulting string is then assigned to the sundaes variable.

Hope this helps! :sparkles:

Gregorio Bernabel
Gregorio Bernabel
3,412 Points

Hello Jennifer, actually I have it the same way. I just thought it was going to show it like you have it in your answer lol

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Yes, but we were composing answers at the same time! I started typing my answer and when I came back your answer was there and posted. If you'd like to learn how I posted my answer so it looks like that, take a look at the Markdown Cheatsheet link at the bottom :arrow_down: of the "Add an Answer" section. And if you want to learn how to do even fancier things than that, take a look at this new Markdown Basics Course here at Treehouse.

Oh, and thanks for your help in the Community! :sparkles:

Gregorio Bernabel
Gregorio Bernabel
3,412 Points

Thank you Jennifer will do, that also happened to me on a different question I answered, someone had posted at the same time

Andrew Zdunek
Andrew Zdunek
432 Points

Thanks so much Gregorio and Jennifer but unfortunately I'm still not coming up with the right answer. I'll move on and come back to this later.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'm unsure why this isn't passing for you. Have you tried reloading the challenge? This was my code for the first step. Or are you working on a different step now?

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

Is your code different in any way? Hope you get this sorted out! :sparkles:

Andrew Zdunek
Andrew Zdunek
432 Points

Hi Jennifer I'm on to indexes now but I will try this later and get back to you :D

Andrew Zdunek
Andrew Zdunek
432 Points

Hey Jennifer just getting back to you - yes that did work and thanks so much :D

Andrew Zdunek
Andrew Zdunek
432 Points

One more question on splitting and joining which so far I obviously need more practice on - Combine the sundaes list into a new variable named display_menu, where each item in the list is rejoined together by a comma and a space (", "). Then reassign the menu variable to use the existing variable and .format() to replace the placeholder with the new string in display_menu.

If you're really brave, you can even accomplish this all on the same line where menu is currently being set.

I ended up doing this on the menu line but my solution doesn't seem to register.

Andrew Zdunek
Andrew Zdunek
432 Points

Menu does not register.

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

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're doing great still! But you have exactly one single extra space. You are joining with a space, a comma, and then another space. You have " , ", but it should be ", " without the first space :thumbsup:

Andrew Zdunek
Andrew Zdunek
432 Points

:D Hey that worked. Ok so attention to detail on Splitting and Joining - got it!!! Thanks Jennifer.