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

adding lists

hi..how do you add your name on a list on python

greeting_list.py

2 Answers

Cristian Altin
Cristian Altin
12,165 Points

The split() function applied to a string generates a list for you by separating items at every space within the string (default behaviour). Just an extra note: list items won't contain any spaces when you use it

I also suggest to re-watch videos when you don't feel like you got something since the exercises build up on things you learned in the previous videos.

Gavin Ralston
Gavin Ralston
28,770 Points

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!

So, the first step would look like so:

full_name = "My Name"

The second part of the challenge is to take that variable full_name and its content up by using the space character as the delimiter (the character to split strings with) and then store that in a new variable called name_list

There's a handy string method called split which should help with that, and this video has a demonstration of that at around the three minute mark.

Thanks Gavin