renumerate documentation¶
renumerate¶
Reverse enumerate.
Overview¶
renumerate(sequence, start=len(sequence)-1, end=0):
Return an enumerate object.
sequence must be an object that has a __reversed__() method or supports the
sequence protocol (the __len__() method and the __getitem__() method with
integer arguments starting at 0).
The __next__() method of the iterator returned by renumerate() returns a tuple
containing a count (from start which defaults to len(sequence) - 1 or ends at
end which defaults to 0 - but not both) and the values obtained from reverse
iterating over sequence.
Usage¶
>>> 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')]
Equivalent to:
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 reversed(sequence):
yield n, elem
n -= 1
Installation¶
Prerequisites:
Python 3.7 or higher
3.7 is a primary test environment.
pip and setuptools
To install run:
python -m pip install --upgrade renumerate
Development¶
Prerequisites:
Development is strictly based on tox. To install it run:
python -m pip install --upgrade tox
Visit development page.
Installation from sources:
clone the sources:
git clone https://github.com/karpierz/renumerate.git renumerate
and run:
python -m pip install ./renumerate
or on development mode:
python -m pip install --editable ./renumerate
License¶
Copyright (c) 2016-2022 Adam KarpierzLicensed under the zlib/libpng LicensePlease refer to the accompanying LICENSE file.
Contents¶
- Changelog
- 1.1.10 (2022-10-18)
- 1.1.9 (2022-08-22)
- 1.1.8 (2022-07-24)
- 1.1.7 (2022-01-10)
- 1.1.6 (2021-12-11)
- 1.1.5 (2021-07-20)
- 1.1.4 (2020-10-18)
- 1.0.13 (2020-09-22)
- 1.0.9 (2019-05-22)
- 1.0.8 (2019-05-21)
- 1.0.7 (2018-11-08)
- 1.0.6 (2018-05-08)
- 1.0.5 (2018-02-26)
- 1.0.4 (2018-01-28)
- 1.0.1 (2018-01-24)
- 1.0.0 (2017-11-18)
- 1.0.0b1 (2017-11-18)
- 0.3.4 (2017-01-05)
- 0.3.3 (2016-09-25)
- 0.3.1 (2016-09-25)
- 0.2.2 (2016-09-24)
- 0.1.1 (2016-09-24)
- 0.0.2 (2016-09-23)