[Tutor] basic Qs [tutorial / text editors / performance chara cteristics]

Scott Widney SWidney@ci.las-vegas.nv.us
Fri Feb 14 10:42:12 2003


> Ok you want a *copy* of a, right? A different object but with equal
> contents. There are various ways. Here goes the simplest:
> 
> b = list(a)
> 
> Here goes another:
> 
> b = []
> for elem in a:
>     b.append(elem)

There's also list slicing:

>>> b = a[:]

and the copy module:

>>> import copy
>>> b = copy.copy(a)

also, use:

>>> import copy
>>> b = copy.deepcopy(a)

for nested lists.


Enjoy!
Scott