Skip to main content

A flexible Python generator function that extends the capabilities of Python's built-in `range` to all types, using customizable comparator and successor functions.

Project description

generalized-range

A flexible Python generator function that extends the capabilities of Python's built-in range to all types, using customizable comparator and successor functions.

Installation

pip install generalized-range

Usage

# coding=utf-8
from __future__ import print_function
from generalized_range import generalized_range

for number in generalized_range(
    start=10,
    stop=14,
    step=1,
    comparator=lambda x, y: x < y,
    successor=lambda x: x + 1
):
    print(number)  # Output: 10, 11, 12, 13

for char in generalized_range(
    start='A',
    stop='F',
    step=2,
    comparator=lambda x, y: ord(x) < ord(y),
    successor=lambda x: chr(ord(x) + 1)
):
    print(char)  # Output: A, C, E

for number in generalized_range(
    start=5,
    stop=1,
    step=1,
    comparator=lambda x, y: x > y,
    successor=lambda x: x - 1
):
    print(number)  # Output: 5, 4, 3, 2

Contributing

If you find a bug or have a new feature you'd like to implement, please feel free to submit a pull request or open an issue.

License

This project is open-source and available under the MIT license. See the LICENSE file for more details.

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

generalized_range-0.1.0a0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

generalized_range-0.1.0a0-py2.py3-none-any.whl (3.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file generalized_range-0.1.0a0.tar.gz.

File metadata

  • Download URL: generalized_range-0.1.0a0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for generalized_range-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 5ed9130b3e7c23d03f2d9756dcfbb8bb4763c314b373215e57a4ab6fb35914df
MD5 b1dca437c3c2cd5e0decdd68fc85a648
BLAKE2b-256 ebb5d51c41141788fd0f4d7f27046710c12334ef4d3cb152b687c991fdbf45d6

See more details on using hashes here.

File details

Details for the file generalized_range-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for generalized_range-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2c8de1ce7c8004e3032e74567dc850a248e2419ca97e81c04a7cbd1651ab0ade
MD5 dc115802d069e8c406fe868c81e9e360
BLAKE2b-256 264cefbfa934f3a65afca54fc448667c562f40817bf925fe649fb5d50618de83

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