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 trialalenwong
4,346 PointsThe 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
Alexander Davison
65,469 PointsIn 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! ~Alex
Vlad Vamos
1,290 PointsI 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]
Alexander Davison
65,469 Pointsprint(a_list[1, 3])
is invalid Python. You probably meant this:
print(a_list[1:3])
alenwong
4,346 PointsThanks all :)