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

Do not understand question - Python

Create a variable named greeting_list that uses the string "Hi, I'm Treehouse" to create a list by splitting on the spaces.

I do not understand what you mean to use a string to create a list by splitting on the spaces. What the question is asking is very unclear to me.

Thanks.

What I think is this, but it fails:

full_name = "Jake Zeal"
name_list = full_name.split()
greeting_list = "Hi, I'm Treehouse"

if greeting_list:
  list.split()

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Split is a method that we can call on a string that will return a list. By default, it will split the string up by whitespace, so it will treat everything between whitespace characters as being an item in the new list.

full_name = "Jake Zeal"
name_list = full_name.split(" ")    # name_list is now a list with the contents ['Jake', 'Zeal']

FYI, if this helps you understand a bit better, the split method lets you also pass in an argument of any other character, and then it would look for that character as the separator between items.

my_string = "123|456|7283748|1|234"         
my_list = my_string.split("|")    # my_list is now a list with the contents ['123', '456', '7283748', '1', '234'] 

Hi Brendon,

I understand what the split method dto create a list by splitting on the spaces."oes. As in the code I shared, I used name_list = full_name.split()

I don't understand, however what the question is asking for, in particular:

"Create a variable named greeting_list that uses the string "Hi, I'm Treehouse" to create a list by splitting on the spaces."

Unless, it is asking for the same thing in step 1 for name_list...

full_name = "Jake Zeal"
name_list = full_name.split()
greeting_list = "Hi, I'm Treehouse".split()

?

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Yes, that's what they are asking for. The difference is that you're calling the split method directly on a string, rather than on a variable that contains a string

Thanks Brandon. I think I was just confused by the wording of the question