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

Help with creating python list automatically.

I need help with this question. 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! I don't know how to do this automatically, I've tried.

full_name = ("Jack Jones")

name_list = list(full_name)

And I don't understand why this does not work!

1 Answer

Hello,

There is a built-in function in python that returns a list of the words in string, separated with a predefined delimiter. The function is string.split(delimiter).

So for your question.

full_name = "Jack Jones"

name_list = full_name.split(" ")

It will output: ["Jack", "Jones"]

In the split() function, you are passing a space as a delimiter " ". If the string was written like that: "Jack,Jones", the you can pass a delimiter "," and it will output the same ['Jack', 'Jones'].

Hope that helps. Good Luck!