Death to tuples!

Duncan Booth duncan.booth at invalid.invalid
Wed Nov 30 05:58:17 EST 2005


Antoon Pardon wrote:
> But lets just consider. Your above code could simply be rewritten
> as follows.
> 
>   res = list()
>   for i in range(10):
>      res.append(i*i)
> 
I don't understand your point here? You want list() to create a new list 
and [] to return the same (initially empty) list throughout the run of the 
program?


> Personnaly I think that the two following pieces of code should
> give the same result.
> 
>   def Foo(l=[]):                def Foo(l):
>     ...                           ...
>     
>   Foo()                         Foo([])
>   Foo()                         Foo([])
> 
> Just as I think, you want your piece of code to give the same
> result as how I rewrote it.
> 
> I have a problem understanding people who find the below don't
> have to be equivallent and the upper must.

The left one is equivalent to:

__anon = []
def Foo(l):
   ...

Foo(__anon)
Foo(__anon)

The left has one list created outside the body of the function, the right 
one has two lists created outside the body of the function. Why on earth 
should these be the same?

Or to put it even more simply, it seems that you are suggesting:

__tmp = []
x = __tmp
y = __tmp

should do the same as:

x = []
y = []



More information about the Python-list mailing list