At 07:28 AM 11/5/03 -0800, Guido van Rossum wrote: > > 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. I thought 'for x in y' always called 'iter(y)', in which case the above still works. It's only this: ef = enumerate(f) while 1: try: i,line = ef.next() print i+1, line, except StopIteration: break That would break.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4