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

String plit

So the question is: Create a variable named greeting_list that's the string "Hi, I'm Treehouse" split on the spaces.

Isnt this the answer? greeting_list = "Hi, I'm Treehouse".split()

greeting_list.py
greeting_list = "Hi, I'm Treehouse".split()

4 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

There are no arguments in split. By default it splits on the white spaces. already.

full_name = "Ryan Stuff"
name_list = full_name.split()

greeting_list = "Hi, I'm Treehouse"
greeting_list = greeting_list.split()

Perhaps the formatting threw you off. But this works for me.

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

You are running split() on a String literal. Try it in a variable first. Like below.

greeting_list = "Hi, I'm Treehouse"
greeting_list = greeting_list.split()

Let me know if that helps solve your issue?

Oh it's cause I didn't include my code from the previous question about splitting your name. When I post your code including your full_name.split() bit it works.

Thanks for the help. :-)

Thanks but that doesn't seem to work either. Here's a screenshot FWIW: http://i.imgur.com/L2KWx0L.png

I also tried it with a space in the split:

spl_string = "Hi, I'm Treehouse"
greeting_list = spl_string.split(' ')

but that didnt work either.