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

Jabari Bellamy
Jabari Bellamy
9,513 Points

How do I use the .split () method to break apart the available string and then assign to new variable sundaes?

I have tried different methods and I keep getting the bummer response. I have added the .split(';') at the end of the available variable and then I have created a new variable called sundaes and I did the exact same thing and added the .split(';') towards the end of the variable and I still got the same response. Any helpful advice would be highly appreciated.

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

4 Answers

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

Hi there, Jabari! You're actually really close here. First, you do not have to add or subtract anything from the first line provided by the challenge. And there's no need to repeat that string as it's already stored in a variable you already have access to. So these things should happen:

  • create the new variable sundaes
  • use the split method on the available variable

Hope this helps but let me know if you're still stuck! :sparkles:

Colton Ancell
Colton Ancell
1,636 Points

I can't remember what the final goal is here, but on your first line split() is splitting on whitespace, of which there is none. On the second line, split(";") is attempting to split on the semi-colon, but each item will have leading whitespace on it. Either try removing the whitespace in the "sundaes" line or use split("; ") with a space after the semi-colon. Hope this helps!

Jabari Bellamy
Jabari Bellamy
9,513 Points

Hello Colton, I actually just tried your way and I still keep getting the bummer response. I didn't think this challenge would be this complex. It looks pretty easy, but I'm still not getting it. I do really appreciate you help though.

Jabari Bellamy
Jabari Bellamy
9,513 Points

Hi Jennifer, thank you for your help, but I'm still stuck. I even tried something new and included the .split(";") with the sundae variable, "sundaes=available.split(";"). And for the available variable I just included the .split() towards the end without adding the quotes around the semicolon inside the .split method parentheses.

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

It looks like you might have tried the correct thing with the caveat that you didn't actually put it in quotation marks as listed above. And yes, the semicolon must be in quotes.

The line you're looking for is:

sundaes = available.split(";")

Keep in mind that this is on a new line and the original line must be left intact. There should be no split() on the first line. If this is what you tried and it's failing, I suggest restarting the challenge and retyping it.

Jabari Bellamy
Jabari Bellamy
9,513 Points

Thank you so much Jennifer. I did as what you said and it worked. I really appreciate your help. Thanks again.