[Tutor] Final review

Steven D'Aprano steve at pearwood.info
Thu May 8 00:57:22 CEST 2014


On Tue, May 06, 2014 at 06:36:21PM +0100, Alan Gauld wrote:

> Aside:
> len() does work with range() and slicing so you can write
> 
> myList[:len(mylist)]
> 
> to get a copy of your list...

Even easier is a blank slice. The start defaults to zero, the 
end to the length of the sequence, and the step to 1, so to make a copy 
of a list is:

myList[:]  # start=0, end=length

or 

myList[::]  # start=0, end=length, step=1


-- 
Steven


More information about the Tutor mailing list