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.0.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.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylistin-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d140a7f4e8727a7651e876555e3baaffec793989b4f502b17099a010deb37086
MD5 d1750abdc42123634748b585e73f5e55
BLAKE2b-256 fd234579aeb1a7b7675a8ff83ec957a68bcc2242db548e55d5a2e897bc400b55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylistin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9135a107028c99b0383338e705bada1a1f910fe6af461a889f12458a3f23ce9c
MD5 21df3d0b0b621a3c171c445e6f20a52d
BLAKE2b-256 d35d80f52277ed406f695dd36ea64c732244d9850f9e90b9ad3fa311ec1cb01f

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