Copy List

Rustom Mody rustompmody at gmail.com
Wed Jul 18 14:56:15 CEST 2007


The standard idiom (I guess) is to use the slice
>>> a=[1,2,3,4]
>>> b=a
>>> b is a
True
>>> b
[1, 2, 3, 4]
>>> c=a[:]
>>> c is a
False
>>> c
[1, 2, 3, 4]

This is shallow copy
If you want deep copy then
from copy import deepcopy



More information about the Python-list mailing list