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 (2016, retired 2019) Slices First Slice

The question asked - Copy the entire list with a slice a_list = [1, 2, 3] a_list ______ what is the answer

The question asked - Copy the entire list with a slice a_list = [1, 2, 3] a_list ______ what is the answer?

I don't understand the question...

3 Answers

In Python, to make a copy of a list using slices, you have to slice from the very start to the very end. You can manually enter the indexes of the start and the finish, but it is easier to use Python's [:] trick:

>>> my_list = [1, 2, 3]
>>> my_list[0:3]  # This makes a copy!
[1, 2, 3]
>>> my_list[:]  # This also makes a copy!
[1, 2, 3]

I hope this helps! :grin: :zap: ~Alex

Vlad Vamos
Vlad Vamos
1,290 Points

I think you need to select the whole list with the slicing method. Slicing example:

a_list = [1, 2, 3]
print(a_list[1:3])
-> [2, 3]
print(a_list[1, 3])

is invalid Python. You probably meant this:

print(a_list[1:3])

Thanks all :)