douglas bagnall wrote:
y = list(x)
y = x[:]
y = [z for z in x]
I think of these, y = list(x) is probably the "right" way.
Actually, x[:] has always been standard, and is faster, at least for
short lists:
[EMAIL PROTECTED]:~$ python -m timeit -s 'x=range(7)' 'x[:]'
1000000 loops, best of 3: 0.332 usec per loop
[EMAIL PROTECTED]:~$ python -m timeit -s 'x=range(7)' 'list(x)'
1000000 loops, best of 3: 0.625 usec per loop
douglas
Possibly, but it assumes x is a list. For non-list objects a slice can
actually return a view of the original. list(x) ensures a shallow copy
that is a list. It also works with any iterable x.
--
Lenard Lindstrom
<[EMAIL PROTECTED]>