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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ed9130b3e7c23d03f2d9756dcfbb8bb4763c314b373215e57a4ab6fb35914df
|
|
| MD5 |
b1dca437c3c2cd5e0decdd68fc85a648
|
|
| BLAKE2b-256 |
ebb5d51c41141788fd0f4d7f27046710c12334ef4d3cb152b687c991fdbf45d6
|
File details
Details for the file generalized_range-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: generalized_range-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c8de1ce7c8004e3032e74567dc850a248e2419ca97e81c04a7cbd1651ab0ade
|
|
| MD5 |
dc115802d069e8c406fe868c81e9e360
|
|
| BLAKE2b-256 |
264cefbfa934f3a65afca54fc448667c562f40817bf925fe649fb5d50618de83
|