PEP 322: Reverse Iteration (second revision, please comment)
Raymond Hettinger
vze4rx4y at verizon.net
Sat Nov 1 12:51:04 EST 2003
[Raymond]
> > * the sample implementation now clearly shows a check for a custom
> > reverse method and a guard against being applied to a mapping.
[Paul Moore]
> I stumbled over this, as using the existence of has_key to reject
> mappings seemed odd. Surely even without this check, the sample
> implementation would fail on a mapping, with a KeyError at the yield?
Without a guard for mappings, the following would behave strangely:
d = {0:'zero', 1:'one', 3:'three'}
Peter Otten pointed-out that some user defined mappings have
__contains__ rather than has_key, so the existence of a "keys"
may make a better check.
> > * added sample output for enumerate.__reversed__ to show
> > how a custom reverse method would work
>
> Are you proposing to add such a custom reverse method to enumerate?
Yes, that has been requested more than once.
However, it was listed in the PEP mainly to give a clear example
of how a custom reverse could work.
> > * explained why the function is proposed as a builtin and why attachment
> > to another module or type object is not being considered further.
>
> This was very useful. It may not convince everyone, but it helped me
> see your point of view a little better.
Thanks.
> > Also, please take a look at the revrange() alternative to see if you
> > prefer it or not.
>
> Not really. It feels too much like a special case.
>
> Overall, I'm +0 going on +1 (the main reason I'm not +1 is the fact
> that I have no code that would actually *use* this feature at
> present...)
Noted.
Raymond
More information about the Python-list
mailing list