[Python-Dev] Re: PEP 322: Reverse Iteration

Guido van Rossum guido at python.org
Wed Nov 5 10:28:01 EST 2003


> Why not change enumerate() to return an iterable, rather than an
> iterator?  Then its __reversed__ method could attempt to delegate to
> the underlying iterable.  Is it likely that anyone relies on
> enumerate() being an iterator, rather than an iterable?

I find it rather elegant to use enumerate() on a file to generate line
numbers and lines together (adding 1 to the index to produce a more
conventional line number).  What's more elegant than

  for i, line in enumerate(f):
      print i+1, line,

to print a file with line numbers???  I've used this in throwaway
code at least, and would hate to lose it.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list