Skip to main content

Reverse enumerate.

Project description

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.

PyPI record.

Documentation.

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:

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-2024 Adam Karpierz
Licensed under the zlib/libpng License
Please refer to the accompanying LICENSE file.

Authors

Changelog

1.2.1 (2024-10-09)

  • Setup (dependencies) update.

1.2.0 (2024-09-30)

  • Drop support for Python 3.8

  • Setup (dependencies) update.

1.1.14 (2024-08-13)

  • Add support for Python 3.13

  • Setup (dependencies) update.

1.1.13 (2024-07-15)

  • Setup (dependencies) update.

1.1.12 (2024-01-26)

  • Setup update (now based on tox >= 4.0).

  • Cleanup.

1.1.10 (2022-10-18)

  • Tox configuration has been moved to pyproject.toml

1.1.9 (2022-08-22)

  • Setup update.

1.1.8 (2022-07-24)

  • Add support for Python 3.10 and 3.11

  • Setup update (currently based mainly on pyproject.toml).

1.1.7 (2022-01-10)

  • Drop support for Python 3.6.

  • Copyright year update.

  • Setup update.

1.1.6 (2021-12-11)

  • Setup update.

1.1.5 (2021-07-20)

  • Setup general update and improvement.

1.1.4 (2020-10-18)

  • Drop support for Python 3.5.

  • Add unittests.

  • Fixed docs setup.

1.0.13 (2020-09-22)

  • Add support for Python 3.8 and 3.9.

  • Drop support for Python 3.4.

  • Setup: fix an improper dependencies versions.

  • Setup general update and cleanup.

1.0.9 (2019-05-22)

  • Drop support for Python 2.

1.0.8 (2019-05-21)

  • Update required setuptools version.

  • Setup update and improvements.

  • This is the latest release that supports Python 2.

1.0.7 (2018-11-08)

  • Drop support for Python 2.6 and 3.0-3.3.

  • Update required setuptools version.

1.0.6 (2018-05-08)

  • Fix a bug in description.

  • Update required setuptools version.

  • Improve and simplify setup and packaging.

1.0.5 (2018-02-26)

  • Improve and simplify setup and packaging.

1.0.4 (2018-01-28)

  • Fix a bug and inconsistencies in tox.ini

  • Update of README.rst.

1.0.1 (2018-01-24)

  • Update required Sphinx version.

  • Update doc Sphinx configuration files.

1.0.0 (2017-11-18)

  • Setup improvements.

  • Other minor improvements.

1.0.0b1 (2017-11-18)

  • Minor improvements.

0.3.4 (2017-01-05)

  • Minor setup improvements.

0.3.3 (2016-09-25)

  • Fix bug in setup.py

0.3.1 (2016-09-25)

  • More PEP8 compliant.

0.2.2 (2016-09-24)

  • Description suplement

  • Minor fixes.

0.1.1 (2016-09-24)

  • First useful release.

0.0.2 (2016-09-23)

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

renumerate-1.2.1.zip (19.7 kB view details)

Uploaded Source

Built Distribution

renumerate-1.2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file renumerate-1.2.1.zip.

File metadata

  • Download URL: renumerate-1.2.1.zip
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for renumerate-1.2.1.zip
Algorithm Hash digest
SHA256 e34ed2b2562903d5d28a19f30adfd0e9f1ec3eb1d242b0d08298774654db410e
MD5 9b6bc76531ad962e7eff41a42d941a6a
BLAKE2b-256 6ffc16f4f7cd7d419f1546e5230cbd863fcf9c27e492d1a0caef52e2529bc5b5

See more details on using hashes here.

File details

Details for the file renumerate-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: renumerate-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for renumerate-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be6743e1d517d29977631856f7b3fe49110918aac0e5a053c73f63b9d8a950f4
MD5 8f63c96c4aeba65212815ccd00a25015
BLAKE2b-256 a2f951d063e72fbd967bc3db190ba36a778b891b1b7eb2996837b7ab94b45ac1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page