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. Advertisements

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:
    925
    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:
    672
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  3. Jim in Arizona
    Replies:
    8
    Views:
    5,238
    Jim in Arizona
    Jan 24, 2006
  4. lurker
    Replies:
    1
    Views:
    858
    Disco Octopus
    Apr 5, 2005
  5. Lyndon
    Replies:
    1
    Views:
    691
    Leonard Blaisdell
    Jul 25, 2005
  6. Patrick Hoffmann
    Replies:
    3
    Views:
    3,202
    Christian Jan├čen
    Aug 8, 2003
  7. kkappabear
    Replies:
    0
    Views:
    194
    kkappabear
    Dec 12, 2006
  8. Ishmael
    Replies:
    4
    Views:
    257
    Ishmael
    Jan 6, 2007
Loading...