[Python-3000] Iterators for dict keys, values, and items == annoying :)
Steven Bethard
steven.bethard at gmail.com
Mon Mar 27 19:55:39 CEST 2006
On 3/26/06, Adam DePrince <adam.deprince at gmail.com> wrote:
> I have a draft PEP and an implementation of mutable iterators for lists
> and dicts that supports delete only.
>
> The PEP (Mutable Iterations) and sample code can be found at:
>
> http://www.deprince.net/ideas/peps.html
I think the PEP really needs a much stronger motivation section,
particularly with real-world examples of code that gets improved by
the additional methods. The whole discussion was spawned by a request
for determining the length of an iterable, a problem which this PEP
doesn't solve at all. What problem is this PEP solving? Is there
real-world code where this PEP would help out?
One of the reasons I'm having trouble imagining it is that especially
for lists, code like::
>>> for c in 'abcdefg':
... l.insert( 0, c )
is almost certainly a bad idea performance-wise due to the Python
implementation of lists. You don't want to repeatedly insert a single
element at the beginning of a list. You'd probably do much better
just writing:
>>> lst = []
>>> lst.extend(reversed('abcdefg'))
>>> lst.extend(l)
Performance matters are probably better in the dict-case, but without
some compelling real-world examples, this really feels like YAGNI to
me.
STeVe
--
Grammar am for people who can't think for myself.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list