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

API

list_reduce <E, T>(list: list[E], callback: (ac: T, item: E, index?: int, list?: list[E]) -> T, ac_init: T) -> 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, 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]]

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-0.0.4.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

pylistin-0.0.4-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylistin-0.0.4.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.11

File hashes

Hashes for pylistin-0.0.4.tar.gz
Algorithm Hash digest
SHA256 847c3e76b7138bda8e399e58db7feaf82bc0961af44ac50c5c7e946920ed2e7a
MD5 e3f1470991813d689e39c421dfe852b4
BLAKE2b-256 0ce543f73223a3518f6b315bd5536aaffb61bcecbf52efc1c6f96b40d26bab05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylistin-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.11

File hashes

Hashes for pylistin-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2a6ede6de3a3d2a26f8cbea7f8c3283259ece300c9dd8d72a3fb7b2a96c90554
MD5 2d3a21e8a6953494b28697d877a9e90d
BLAKE2b-256 a9ef836e2fd0b1608de9071d56be4e465dced220f08d6c2f75e483aba342ebde

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