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

zakaria arr
zakaria arr
6,347 Points

How do you change 'Treehouse' in your greeting list to the first item of your name_list

If I add append my first name from name_list into greeting list 'Treehouse' will still be there.

greeting_list.py
full_name = 'zakaria arr'
name_list = ['zakaria', 'arr']

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

1 Answer

The split method turns a string into an array. In your code, greeting_list is the following array: ['Hi,', "I'm", 'Treehouse']

Individual items in an array can be accessed directly using bracket notation. This is written by following the array with [], with the index number for the item in the array. Array indexes start with zero. So to get the first item of name_list, you use:

In Python, individual items in an array can also be set using bracket notation. So if you want to change 'Treehouse' in the greeting_list array to the first item in the name_list array, you simply set the last item in greeting_list equal to the first item in name_list.

```greeting_list[2] = name_list[0]```