Thought on PEP 204 and 276

Terry Reedy tjreedy at udel.edu
Tue Jun 4 22:40:00 EDT 2002


"Stephen Horne" <steve at lurking.demon.co.uk> wrote in message
> The special behaviour is  the [] cannot create a new item in a list

Actually ...

>>> a = range(3)
>>> a[2:2] = [9]
>>> a
[0, 1, 9, 2]
>>> a[4:4] = [8] # to not disturb existing mapping
>>> a
[0, 1, 9, 2, 8]

To me, this supports your main point ...

> The origin of this thread was the idea of supporting the items()
> method for lists in the same way as it is for dictionaries instead
of
> adding an enumerate function. There is no relative performance hit
> whichever notation is used. Being consistent in how key-to-value
> mapping types represent their functionality has no performance cost
at
> all.
>
> If there was a performance hit in what I was suggesting, I'd say
that
> pragmatics were in your favor. Without that performance hit, perhaps
> pragmatics may have more to do with the learning curve.
>
> Someone who has written something like...
>
>   for key, value in l_Dict.items () :
>
> might well try to do the same for a list. Why have two ways to do
the
> same thing?

I agree completely that the 'same' operation should have the same name
for all types it can apply to.

Terry J. Reedy






More information about the Python-list mailing list