how to force a list to be local?

Mark Harrison mh at dreadnok.pixar.com
Fri Aug 6 01:57:07 CEST 2004


In the following code, t1 does not modify b, while t2 seems to
modify b.  What do I need to do in order to make b local in t2
so that b.remove() does not modify the passed in list?

def t1(a,b):
    b = []

def t2(a,b):
    b.remove(4)


a=[1,2,3]
b=[4,5]

t1(a,b)
print a,b

t2(a,b)
print a,b

results:
[1, 2, 3] [4, 5]
[1, 2, 3] [5]

Many TIA!
Mark

-- 
Mark Harrison
Pixar Animation Studios



More information about the Python-list mailing list