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 trialLauren Reinstein
Courses Plus Student 198 Pointscannot figure out how to split this string
I have tried everything I have learned thus far, cannot figure this out. Someone please help!
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
Front End Web Development Techdegree Graduate 33,271 Pointsinstead 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.
macmondiaz
1,415 PointsHello 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!