Skip to content

Repository files navigation

Repeatable

Python package to create generator-like objects that can be iterated over more than once.

Repeatable also provides itertools alternatives that handle thase iterables with far better memory efficiency, even accepting infinite iterables.

Installation

pip install repeatable

Usage

Creating a repeatable Fibonacci-number generator:

fromrepeatableimportrepeatable@repeatabledeffibonacci(max_value=5):
a, b, =0, 1whilea<=max_value:
yieldaa, b=b, a+brepeatable_fibonacci=fibonacci()
forxinrepeatable_fibonacci:
print(x)
repeatable_fibonacci.restart()
foryinrepeatable_fibonacci:
print(y)
"""011235011235"""

You can also use repeatable itertools on infinite generators:

fromrepeatableimportrepeatable, product@repeatabledeffibonacci():
a, b=0, 1whileTrue:
yieldaa, b=b, a+brepeatable_fibonacci=fibonacci()
forpinproduct(repeatable_fibonacci, range(2)):
print(p)
"""(0, 0)(0, 1)(1, 0)(1, 1)(1, 0)(1, 1)(2, 0)(2, 1)(3, 0)(3, 1)(5, 0)(5, 1)..."""

About

Python package to create generator-like objects that can be iterated over more than once.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages