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.1.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file loop-python-0.1.1.tar.gz
.
File metadata
- Download URL: loop-python-0.1.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e95a9a5bb439c17df7b48b97180fd418252abc4b6223123c27d76551db933a |
|
MD5 | c2ea158f35345ecd43a4a1cb0f678424 |
|
BLAKE2b-256 | 776a5d250165db5d3109e639ead479c6715ecfec993d6ff7e34c37ea29a3cf13 |
File details
Details for the file loop_python-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: loop_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.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 | 3c32024bfa89776af8fb35d2d281d44884726d2764a6d1f2a35fd668fd076ad0 |
|
MD5 | fdfd4cc7c37ea7df00c4d1e80c81bb79 |
|
BLAKE2b-256 | dfcda47698df3f7ca979acd41757a3abed45be9db57324fadf36bc57429e11e2 |