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 Collections (Retired) Slices Deleting Or Replacing Slices

Slice assignment with list

In the lecture example, Ken replaces a slice with a list containing a single string (my_list[8:10] = ['i']) The updated my_list contains the string, 'i', at positions 8 and 9. However, if I perform a replacement such as my_list[4] = ['i'], my_list would contain, not the string 'i', but the one element list ['i']. What's going on?

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

My example replaces a slice, your example replaces an index. You could do my_list[4:5] = ['i'] and get the 'i' in position 4. This is also replacing a slice (note the :)

Got it. Thanks.