On Wed, 2003-11-05 at 15:56, Alex Martelli wrote: > def reversed(sequence): > for x in xrange(len(sequence)-1, -1, -1): yield sequence[x] > > no __reversed__, no complications, "no nuttin'". If I was adding this as a library routine, I'd do: def reversed(sequence): try: seqlen = len(sequence) except TypeError: sequence = list(sequence) seqlen = len(sequence) for x in xrange(seqlen-1, -1, -1): yield sequence[x] OK, inefficient for iterators on long sequences, but it works with enumerate() etc and needs no changes to existing types. Mark
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