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


Release history Release notifications | RSS feed

This version

2.4.3

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.4.3.tar.gz (13.7 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.4.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for renumerate-2.4.3.tar.gz
Algorithm Hash digest
SHA256 7d5867bae9f56d35b46736815aa5a672b904283b83b23081eeb3b488848924ff
MD5 7b56fd0db434ff84ece265b90834b8ed
BLAKE2b-256 65beb37a6983d3db0155439da6595f8bf5ff0b43cc698216eb81681a80b74b43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: renumerate-2.4.3-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.13

File hashes

Hashes for renumerate-2.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 62b86cc7defaef735e8fd4beec2d7a87b384d3a06fa4dc6521bd0b567edf8e0a
MD5 9247c2eb2e0acfc3be598ecba39dff2b
BLAKE2b-256 eb7f4be405b5f50f63f9ede0f770f8f5aa7069c640a55a0f714c6a5e3d4bc786

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