Does anyone else use this little idiom?

miller.paul.w at gmail.com miller.paul.w at gmail.com
Sun Feb 3 12:29:30 EST 2008


On Feb 3, 11:20 am, Paul McGuire <pt... at austin.rr.com> wrote:

[... some code... some words ... more code, etc. ...]

> But this still seems like a lot of work to avoid "for x in range(n):".

I agree.  The point of me using "for _ in xrange (n)" isn't to avoid
the for loop at all.  What I wanted was a pythonic way to express only
the necessary components of the loop, like the Ruby version "n.times
do { stuff }"  does.  There's no explicit index in the Ruby code,
because you don't care about it.

Now, if you could monkeypatch built-ins, I'd *almost* consider adding
a .times method to integers. But, of course, monkeypatching is evil. :-
>



More information about the Python-list mailing list