renumerate (sequence, start=len(sequence)-1, end=0):
Return an enumerate object.sequence must be an object that has a __reversed__() method or supports thesequence protocol (the __len__() method and the __getitem__() method withinteger arguments starting at 0).The __next__() method of the iterator returned by renumerate() returns a tuplecontaining a count (from start which defaults to len(sequence) - 1 or ends atend which defaults to 0 - but not both) and the values obtained from reverseiterating over sequence.
>>> from renumerate import renumerate >>> seasons = ['Spring', 'Summer', 'Fall', 'Winter'] >>> list(renumerate(seasons)) [(3, 'Winter'), (2, 'Fall'), (1, 'Summer'), (0, 'Spring')] >>> list(renumerate(seasons, start=4)) [(4, 'Winter'), (3, 'Fall'), (2, 'Summer'), (1, 'Spring')] >>> list(renumerate(seasons, end=2)) [(5, 'Winter'), (4, 'Fall'), (3, 'Summer'), (2, 'Spring')]
def renumerate(sequence, start=None, end=None): if start is not None and end is not None: raise TypeError("renumerate() only accepts start argument or end argument" " - not both.") if start is None: start = len(sequence) - 1 if end is None: end = 0 n = start + end for elem in sequence: yield n, elem n -= 1
$ pip install --upgrade renumerate
zlib/libpng LicensePlease refer to the bundled LICENSE file.
- Minor setup improvements.
- Fix bug in setup.py
- More PEP8 compliant
- Description suplement
- Minor fixes.
- First beta release.
- Initial release.