Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plumdog/python-integer-tuple-generator
Efficiently generate tuples of integers
https://github.com/plumdog/python-integer-tuple-generator
Last synced: about 2 months ago
JSON representation
Efficiently generate tuples of integers
- Host: GitHub
- URL: https://github.com/plumdog/python-integer-tuple-generator
- Owner: plumdog
- License: mit
- Created: 2015-04-15T20:20:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-05T22:05:08.000Z (over 9 years ago)
- Last Synced: 2024-10-14T02:27:24.496Z (3 months ago)
- Language: Python
- Size: 152 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# python-integer-tuple-generator
Efficiently generate tuples of integers.If you want to iterate over all possible tuples of integers that sum
upto a given value, you've come to the right place.Install with `pip install integer-tuple-generator`
Then iterate as follows:
```python
import integer_tuple_generator# To iterate over all 3-tuples that have sum less-than or equal to 100
for a, b, c in integer_tuple_generator.ints(3, upto_sum=100):
print(a, b, c)
```The integers are also guaranteed to be generated in sorted order.
At present, this is slightly slower than nested for-loops, if you
include the necessary temporary sums and checks (see
`performance_tests.py`) but this makes it easy to loop over a
dynamic-number of integers.TODO
----
See if there are ways to make it faster. Either in Python or Cython.