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 First Slice

Julian Garcia
Julian Garcia
18,380 Points

What is wrong with list copy?

a_list = [1, 2, 3]

a_list =a_list[:]

Copy the entire list with a slice.

1 Answer

Frederik Andersen
Frederik Andersen
10,012 Points

Hi Julian.

You can use the index to copy the list.

a_list = [1, 2, 3]
a_list[0:3]

This will copy the list from index0 to index 2. The last number should be 1 higher than the last index you want to copy.

or

a_list = [1, 2, 3]
a_list[:]

Hope this helps :)

Frederik

Julian Garcia
Julian Garcia
18,380 Points

Frederik,

that solves the problem.

Thank you.