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.4.0.tar.gz
(16.7 kB
view details)
Built Distribution
File details
Details for the file loop-python-0.4.0.tar.gz
.
File metadata
- Download URL: loop-python-0.4.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec461126977a7809524b2f5f5946d930444bbb7bf4e4a79a262de4bca5ce210b |
|
MD5 | 3e61bcf31c559f857633852d1f5a2c47 |
|
BLAKE2b-256 | 61ddfdbd6ea33d2096b1b497ed4b0dd4911c3264cac047cc31209ef4a2b95386 |
File details
Details for the file loop_python-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: loop_python-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a53dcfd55d0ce75e4fb9a1a7a09eb397fe032b7a7847e0bb77cbf681e27bd08a |
|
MD5 | 3ee286e85e78156e94208ce2eccc7f97 |
|
BLAKE2b-256 | 76e63a623a31aa361822a0b88506f40e0bf0cee75a29efe2b6cbec9e375eb8e9 |