Replace common looping boilerplate with pretty method chaining.
Project description
Welcome to loop
Replace common looping boilerplate with pretty method chaining.
Installation
pip install loop-python
Documentation
Visit the documentation site.
Example
Loop over range(20)
, apply the fibo()
function and then, on top of it, apply the fizzbuzz()
function, finally, apply print()
:
from loop import loop_over
def fizzbuzz(x):
rules = {3: 'fizz', 5: 'buzz'}.items()
res = ''.join(word for div, word in rules if x%div == 0)
return res if res else x
def fibo(x):
a, b = 1, 1
for _ in range(1, x):
a, b = b, a + b
return b
loop_over(range(20)).map(fibo).map(fizzbuzz).map(print).exhaust()
Will produce the following output:
1
1
2
fizz
buzz
8
13
fizz
34
buzz
89
fizz
233
377
buzz
fizz
1597
2584
4181
fizzbuzz
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
loop-python-0.2.1.tar.gz
(8.8 kB
view details)
Built Distribution
File details
Details for the file loop-python-0.2.1.tar.gz
.
File metadata
- Download URL: loop-python-0.2.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9954a2e4acc4c5c91db2cb2626e201732a1159524d3f21304fbef178c4d7b26e |
|
MD5 | 8ca78bb089f9c00999bba37d9c7697ba |
|
BLAKE2b-256 | f977e5c76005c002b3b702a114dfa225cbac662c94c8085597f69c001096fb71 |
File details
Details for the file loop_python-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: loop_python-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2aa84aa2a1a957871614588edcdfb5769ef7af2096985926df0574260e6bf6d |
|
MD5 | 031c7723780827299535ad036a8ecc30 |
|
BLAKE2b-256 | bc6353fb4525b398f46e20f86a1a24ac591d32c14da3e9bbdf66ae817266068d |