Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Shopping List Lists and Strings

Anthony Macias
Anthony Macias
11,220 Points

stuck on list challenge

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!

6 Answers

So.... what's your question?

name_list --> this should equal the first, middle and last name as list elements. However you shouldn't just type them in. That's so 1980's.

Check this out and see if you can apply it to your full_name variable.

<pre>

>>> word = "This is some random text"

>>> words2 = word.split(" ")

>>> words

['This', 'is', 'some', 'random', 'text']
</pre>

You can use the split() method on your full_name variable.

Tony Brackins
Tony Brackins
26,685 Points

full_name = "Full Name" name_list = full_name.split(" ")

Mark Long
Mark Long
15,762 Points

The first challenge passed with:

full_name = "Steven Mark Long" name_list = full_name.split(" ")

Then when I attempted to answer the second challenge I received a message that says "Oops! It looks like Task 1 is no longer passing."

What gives?

Daniel Chan
Daniel Chan
11,787 Points

Yes you can do it simply like this:

full_name = 'Firstname Middlename Lastname'
name_list = ' '.split(full_name)
>>>name_list
['Firstname', 'Middlename', 'Lastname']
Aman Kumaran
Aman Kumaran
2,314 Points

you have used the wrong code, that type of code is for join, not split :)

Aman Kumaran
Aman Kumaran
2,314 Points

you have used the wrong code, that type of code is for join, not split :)

Aman Kumaran
Aman Kumaran
2,314 Points

you have used the wrong code, that type of code is for join, not split :)