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
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.1.3.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file loop-python-0.1.3.tar.gz
.
File metadata
- Download URL: loop-python-0.1.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fab474015848ccee326c5430dc21c3f60b81efe25592e43b356f2245213170f |
|
MD5 | b27c76cc50ff78c7a9a9f2f4230786b5 |
|
BLAKE2b-256 | 5a20263bdeb6e3edc551d31216413e59dd6a2000c40d8c7b20fd1c682492ad4d |
File details
Details for the file loop_python-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: loop_python-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.3 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 | 672317c7e4bed60828d9d8448ac6c0310b32805838ec645c9e8a26c62a64e4ec |
|
MD5 | ad9a0a8268dcf898d90d89f26a07b719 |
|
BLAKE2b-256 | cbaf6b43ff13bd1972076a1996c319a6b5ba9bf78b5baa117c1a475fea62dd72 |