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 nox. To install it run:

    python -m pip install --upgrade nox

Visit Development page.

Installation from sources:

clone the sources:

git clone https://github.com/karpierz/renumerate renumerate

and run:

python -m pip install ./renumerate

or on development mode:

python -m pip install --editable ./renumerate

License

Copyright (c) 2016-2026 Adam Karpierz
Licensed under the zlib/libpng License
Please refer to the accompanying LICENSE file.

Authors

Sponsoring

If you would like to sponsor the development of this project, your contribution is greatly appreciated.
As I am now retired, any support helps me dedicate more time to maintaining and improving this work.

Donate

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-2.2.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

renumerate-2.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file renumerate-2.2.0.tar.gz.

File metadata

  • Download URL: renumerate-2.2.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for renumerate-2.2.0.tar.gz
Algorithm Hash digest
SHA256 0ad3e4c3b8c92be7acd030f11dd8252fbf1473edc52e4480000ada01af7ade73
MD5 94c3aba34de9e23446b47ede4c348067
BLAKE2b-256 f27495e6aa411161b0330d946cf4ad0714655e25da9ccf6c9970ce5c2851da04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: renumerate-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for renumerate-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 501330e961c79c4c1143fe21c9e4a4c312df5cf737ff1efba65b81360e873ec4
MD5 6c2f055ace1c6ff94d5b99fb7b033f6f
BLAKE2b-256 7697b6b334b4fa0e24cdae3001bfae84940636cf65a55b77f8a71d3b1d1c684f

See more details on using hashes here.

Supported by

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