how to force a list to be local?

Discussion in 'Python' started by Mark Harrison, Aug 6, 2004.

  1. 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
     
    Mark Harrison, Aug 6, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    1
    Views:
    779
    George Ter-Saakov
    Jun 26, 2003
  2. =?Utf-8?B?WVNVVA==?=

    Access local port or Running local exe file

    =?Utf-8?B?WVNVVA==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    526
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  3. Jim in Arizona
    Replies:
    8
    Views:
    4,983
    Jim in Arizona
    Jan 24, 2006
  4. kkappabear
    Replies:
    0
    Views:
    114
    kkappabear
    Dec 12, 2006
  5. Ishmael
    Replies:
    4
    Views:
    178
    Ishmael
    Jan 6, 2007
Loading...

Share This Page