PEP 322: Reverse Iteration (second revision, please comment)
Paul Moore
pf_moore at yahoo.co.uk
Fri Oct 31 17:56:05 EST 2003
"Raymond Hettinger" <vze4rx4y at verizon.net> writes:
> The key changes are:
>
> * reversed() is being preferred to ireverse() as the best name.
Good. The explanation of why reverse() is not an option helps, too.
> * the sample implementation now clearly shows a check for a custom
> reverse method and a guard against being applied to a mapping.
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?
> * 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?
> * 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.
> Please continue to contribute your thoughts. I'm especially interested
> in people examining their own code to verify that the new function
> adds clarity and improves performance.
I don't think I have any real cases where I'd use this. But I agree
with your comments, that this "feels like" a basic looping construct.
> 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...)
Paul,
--
This signature intentionally left blank
More information about the Python-list
mailing list