how to force a list to be local?

M

Mark Harrison

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top