possible python bug here

Peter Kleiweg in.aqua.scribis at nl.invalid
Sun Aug 29 17:16:59 CEST 2004


manuel schreef:

> In the sample below, the foo function modify the b list,
> but I think it should modify only c, not b! It work
> correctly if if b is one dimension list instead two.
>
> def foo(aList):
>      print "use foo..."
>      aList[2][0] += .35
>      aList[2][1] += .35
>      aList[2][2] += .35
>
> p = [2.5,2.5,2.5]
> b = [p,p,p,p]
>
> c=b[:] #c is a totally new list cloned from b, it's not an alias!

No it isn't. You didn't make a deep copy.



-- 
Peter Kleiweg  L:NL,af,da,de,en,ia,nds,no,sv,(fr,it)  S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

The Halloween Documents: http://www.opensource.org/halloween/




More information about the Python-list mailing list