reverse_enumerate is prettier

bzr revid: christophe@tinyerp.com-20080818075602-m9izdakbstgc2qq2
This commit is contained in:
Christophe Simonis 2008-08-18 09:56:02 +02:00
parent ae36063314
commit 4a72330cc6
1 changed files with 16 additions and 16 deletions

View File

@ -290,22 +290,22 @@ def flatten(list):
r.append(e) r.append(e)
return r return r
reverse_enumerate = lambda l: izip(xrange(len(l)-1, -1, -1), reversed(l)) def reverse_enumerate(l):
reverse_enumerate.__doc__ = \ """Like enumerate but in the other sens
"""Like enumerate but in the other sens >>> a = ['a', 'b', 'c']
>>> a = ['a', 'b', 'c'] >>> it = reverse_enumerate(a)
>>> it = reverse_enumerate(a) >>> it.next()
>>> it.next() (2, 'c')
(2, 'c') >>> it.next()
>>> it.next() (1, 'b')
(1, 'b') >>> it.next()
>>> it.next() (0, 'a')
(0, 'a') >>> it.next()
>>> it.next() Traceback (most recent call last):
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <module> StopIteration
StopIteration """
""" return izip(xrange(len(l)-1, -1, -1), reversed(l))
#---------------------------------------------------------- #----------------------------------------------------------
# Emails # Emails