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

Ratheesh Mukundan
Ratheesh Mukundan
2,140 Points

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

please help me to solve this question...

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

When a string literal is created it has all of the methods and attributes of other strings so you can use the .split() method directly. No argument to split() is necessary because "on spaces" is the default.

# Task 2 of 4
# Create a variable named 'greeting_list' that uses the string
# "Hi, I'm Treehouse" to create a list by splitting on the spaces.
greeting_list = "Hi, I'm Treehouse".split()

When I use this code, it returns

"Bummer! Your greeting_list doesn't have the right content. Did you split the string "Hi, I'm Treehouse"?"

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Josh. Can you post exactly the code you've used for task 1 and 2?

luis Cabrera
luis Cabrera
802 Points

You need to split on the spaces. Use split(" ")

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Correct. Note that splitting on whitespace is the default action if non sep separation argument is given. (docs)