Functions to work with list in python
Project description
PYLISTIN
Functions to work with list in python
Install
pip install pylistin
API
list_reduce <E, T>(list: list[E], callback: (ac: T, item: E, index?: int, list?: list[E]) -> T, ac_init: T = 0) -> T
For each all list elements with a lamda function or def as callback for return a one result.
This function is used to loop through a list and accumulate a value.
from pylistin import list_reduce
print(list_reduce([2,5,9], lambda ac, item, i, list: ac + item, 0)) # 16
list_map <E, T>(list: list[E], callback: (item?: E, index?: int, list?: list[E]) -> T) -> list[T]
For each all list elements with a lamda function or def as callback for return an other list with same lenght.
from pylistin import list_map
print(list_map([2,5,9], lambda item, i: i, 0)) # [0, 1, 2]
list_filter <E>(list: list[E], callback: (item?: E, index?: int, list?: list[E]) -> boolean) -> list[E]
For each all list elements with a lamda function or def as callback for return only elements that callback return True.
from pylistin import list_filter
print(list_filter([
{"id": 1, "enabled": 1},
{"id": 2, "enabled": 1},
{"id": 3, "enabled": 0},
{"id": 4, "enabled": 1}
], lambda item: item["enabled"] == 1))
# [{'id': 1, 'enabled': 1}, {'id': 2, 'enabled': 1}, {'id': 4, 'enabled': 1}]
list_group <E, T>(list: list[E], callback: (item?: E, rows?: list, last_row?: int, this_column?: int , index?: int, list?: list[E]) -> T, columns: int ) -> list[T]
For each all list elements with a lamda function or def as callback for agruping a list in rows and columns.
from pylistin import list_group
print(list_group([4,5,9,2,5,9,1,2,3], lambda item: item, 3))
# [[4, 5, 9], [2, 5, 9], [1, 2, 3]]
Updates
[0.0.5] changes
- implement a
for item in listwithoutrangeinlist_reduceandlist_group. - reducing the exceptions and determinate the arguments of
callbacks.
Lisence
MIT
Author
Camilo Andres Barbosa - calimpio
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylistin-0.0.5.tar.gz.
File metadata
- Download URL: pylistin-0.0.5.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f01565133c42b9c123bcd319910bc5e26629255205710e999758223c24a8b480
|
|
| MD5 |
bd01f0c60ad59c8951047ba01dbfa267
|
|
| BLAKE2b-256 |
4a9180ada70ef6205bca4a7b37e92bfcc80aae6fb56b34ea4b64db68decf1f4c
|
File details
Details for the file pylistin-0.0.5-py3-none-any.whl.
File metadata
- Download URL: pylistin-0.0.5-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa12f17f76f787636a3267c2c19eda20ce3213d13743508d8e47285730e73b94
|
|
| MD5 |
b13a2d7e468d6aea2f5a2114543633ee
|
|
| BLAKE2b-256 |
195a01509c54d1a937125b3b94cdac21e6a19f7e5191fa543acb166c848bf7aa
|