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 (Retired) Shopping List Lists and Strings

Create a variable named full_name that holds your full name. Make another variable named name_list that holds your full

Create a variable named full_name that holds your full name. Make another variable named name_list that holds your full name as a list, split on the spaces. Don't create name_list manually!

any suggestions? Thx

greeting_list.py
full_name = "peter gabriel"
name_as_list = list(full_name)
name_list = name_as_list ''.split(name_as_list)

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Oscar,

To create a list using the full_name variable you simply just need to pass a string to the split method which consists of a space.

full_name = 'peter gabriel'
name_list = full_name.split()

EDIT: updated as per Mr. Loves comment below :)

Happy coding!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

.split() will actually split on spaces (and tabs and new lines) by default, no arguments required!

Chris Shaw
Chris Shaw
26,676 Points

Thanks Kenneth Love, it's been a couple of months since I used Python, time for a refresh me thinks.