Skip to main content

Functions to work with list in python

Project description

PYLISTIN

Functions to work with list in python

Install

  • pip install pylistin

Update to last version

  • pip install pylistin --upgrade

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 list without range in list_reduce and list_group.
  • reducing the exceptions and determinate the arguments of callbacks.

Lisence

MIT

Author

Camilo Andres Barbosa - calimpio

cab331@hotmail.com

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

pylistin-1.0.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylistin-1.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file pylistin-1.0.1.tar.gz.

File metadata

  • Download URL: pylistin-1.0.1.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

Hashes for pylistin-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6aed802e428e79a67fee7e24671542974a717b88ffe437a6d1f1fd710e6b481e
MD5 85db47915cb77bddcea8a129d1b79abb
BLAKE2b-256 d9a8d074e753a0e3c6e3bb6078dd7403a3c2a77be3cdd61c0d8d3aca60028cbd

See more details on using hashes here.

File details

Details for the file pylistin-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pylistin-1.0.1-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

Hashes for pylistin-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ba367be23a54f4b202e06426d27645422f62bdd59795a4000253cdad8035ed2
MD5 4a04e7cf0cf9e92905a63546b60d983f
BLAKE2b-256 0829cdfa2a8270107fdfe816266810da46a07dbc2945162406ae547ba1f937e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page