PEP 322: Reverse Iteration (second revision, please comment)
Werner Schiendl
ws-news at gmx.at
Thu Oct 30 06:29:44 EST 2003
Alex Martelli wrote:
>
> A built-in iterator irange -- with an optional "reverse=" argument,
> just like the very useful one you recently added to list.sort -- would be
> just as useful as revrange for the latter's use cases, AND be very handy to
> me in many more cases in which I currently use xrange and cringe each and
> every time. Plus, specifically, I have some uses cases where:
>
> if mustbereversed(...):
> seq = xrange(N-1, -1, -1)
> else:
> seq = xrange(N)
> for item in seq:
> ...
>
> and those would get a somewhat minor benefit from either reverse OR
> revrange, since the if/else to prepare seq would still be there,
> albeit more readable along one of the two branches. However, for this
> kind of use case, an irange with an optional reverse= would be PERFECT:
>
> for item in irange(N, reverse=mustbereversed(...)):
> ...
>
> now THAT would be blissful indeed.
>
+1
I'd definitely prefer such a general approach to having "revrange"
However, I think it's no direct replacement for "reversed"
regards
Werner
More information about the Python-list
mailing list