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

How do you change "Treehouse" in greeting_list to the first value in the name_list variable

I can't seem to figure this step out. someone help

greeting_list.py
full_name = "Paul Vitalis Onyango"
name_list = full_name.split()
greeting_list = "Hi, I'm Treehouse".split()
paul = greeting_list.find("Treehouse")
greeting_list[paul] = name_list[0]

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Lists are 0-indexed, so the first item has the index of 0, the second has an index of 1, and so on. greeting_list is a list (hence the name), and has three members, so what would be the index of the last item, which is the string 'Treehouse'?

You can overwrite what's in an index by assigning to that index. If we assume foo is a list and has 5 items in it, I can change the last item to the string 'hello' with foo[4] = 'hello'.