Death to tuples!
Antoon Pardon
apardon at forel.vub.ac.be
Thu Dec 1 04:35:45 EST 2005
On 2005-11-30, Christophe <chris.cavalaria at free.fr> wrote:
> Antoon Pardon a écrit :
>> On 2005-11-30, Duncan Booth <duncan.booth at invalid.invalid> wrote:
>>
>>>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?
>>
>>
>> No, but I think that each occurence returning the same (initially empty)
>> list throughout the run of the program would be consistent with how
>> default arguments are treated.
>
> What about that :
> def f(a):
> res = [a]
> return res
>
> How can you return the same list that way ? Do you propose to make such
> construct illegal ?
I don't propose anything. This is AFAIC just a philosophical
exploration about the cons and pros of certain python decisions.
To answer your question. The [a] is not a constant list, so
maybe it should be illegal. The way python works now each list
is implicitely constructed. So maybe it would have been better
if python required such a construction to be made explicit.
If people would have been required to write:
a = list()
b = list()
Instead of being able to write
a = []
b = []
It would have been clearer that a and b are not the same list.
--
Antoon Pardon
More information about the Python-list
mailing list