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

Lauren Reinstein
PLUS
Lauren Reinstein
Courses Plus Student 198 Points

cannot figure out how to split this string

I have tried everything I have learned thus far, cannot figure this out. Someone please help!

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

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

instead of repeating the flavors, use the variable name they are assigned to. then, the split method takes an argument (as a string) that is the delimiter, which is the character (comma, space, etc) used to separate the elements in whatever it is you are splitting, so it knows where you want the splits to occur.

https://docs.python.org/3/library/stdtypes.html#str.split

macmondiaz
macmondiaz
1,415 Points

Hello Lauren! since your string looks like it's being separated by semi colon, then you need to use semi-colon as the splitter. which will look like this .split(';')

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

print (sundaes)

code above will print:

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

Hope this helps!