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

How do I split lists?

I'm having a hard time splitting lists.

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

You are really close but you had the split backwards.

Think of it this way, whatever the .split gets attached to gets split. So if you attach .split(';') to the variable available, the list will get split up. Like this:

>>> available.split(';')
['banana split', 'hot fudge', 'cherry', 'malted', 'black and white']

This however, only returns a list of the items split up. You then need to assign this list to a variable, called sundaes:

>>> sundaes = available.split(';')
>>> print(sundaes)
['banana split', 'hot fudge', 'cherry', 'malted', 'black and white']

Once assigned, the variable sundaes now represents the list and can be called whenever you need a list of the sundaes. :)

I hope that helps!