Skip to main content
Help us improve Python packaging – donate today!

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.
>>> 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 sequence:
        yield n, elem
        n -= 1

Installation

Prerequisites:

To install run:

python -m pip install --upgrade renumerate

Development

Visit development page

Installation from sources:

Clone the sources and run:

python -m pip install ./renumerate

or on development mode:

python -m pip install --editable ./renumerate

Prerequisites:

  • Development is strictly based on tox. To install it run:

    python -m pip install tox
    

License

Copyright (c) 2016-2018 Adam Karpierz

Licensed under the zlib/libpng License
Please refer to the accompanying LICENSE file.

Authors

Changelog

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.

Release history Release notifications

This version
History Node

1.0.5

History Node

1.0.4

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
renumerate-1.0.5.zip (11.5 kB) Copy SHA256 hash SHA256 Source None Feb 26, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page