extended list methods
Project description
Listrology
name is suggested by our good friend chatgpt Listrology extends the functionality of lists
Installation
pip install listrology
Usage
Listrology contains a subclass of list which provides a number of methods that are useful
from listrology import List
assert List([1, 2, 3]) == [1, 2, 3]
Square bracket prefix is also supported
from listrology import List
assert List[4, 5, 6] == [4, 5, 6]
There is also a shorthand constructor
from listrology import L, List
assert L[7, 8, 9] == List[7, 8, 9] == [7, 8, 9]
Some methods include
mylist = L[0, 1, 2, 3, 4, 5, 6]
mylist.foreach(print) # prints all elements one by one
mylist.reject(lambda x: x == 2) # [0, 1, 3, 4, 5, 6]
# copy elements mylist[5:7] and use it to overwrite elements starting at mylist[1]
mylist.overwrite(target=1, start=5, end=7) # [0, 5, 6, 3, 4, 5, 6]
mylist.first(lambda x: x % 2 == 1) # 1 (first one that is odd)
mylist.fill("yo", 2, 4) # [0, 1, "yo", "yo", 4, 5, 6]
# each rotation the first element is put to last (inspired by Ruby)
mylist.rotate(1) # [1, 2, 3, 4, 5, 6, 0]
mylist.rotate(2) # [2, 3, 4, 5, 6, 0, 1]
listrology's lists supports method chaining (each method produces a new instance)
volcano_heights = L[412, 399, 276, 591, 482, 451, 521, 529, 521, 426, 511, 426, 426]
# find all volcano heights that are 400m-525m tall and remove duplicates and sort then
result = volcano_heights.filter(lambda x: 400 <= x <= 525).unique().sort()
# [412, 426, 451, 482, 511, 521]
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
listrology-1.0.1.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file listrology-1.0.1.tar.gz
.
File metadata
- Download URL: listrology-1.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a964e429a90c1c7d9d5c9ec5d2fd3f54febcaf627b64999beb9c908b7a290591 |
|
MD5 | dc90f1369fae5abfd66147ced201946d |
|
BLAKE2b-256 | f2b2dcbf87a1eb7459bbe4f5d4a3b15e9d4831089ad0ca329cbccc5056226e66 |
File details
Details for the file listrology-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: listrology-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9051c331c19f9dcf5348c673edd61cd512f7c165c4c07c2a6d09bd38da6b5f1e |
|
MD5 | 942a3df636f242df4e07ddfa1c12549f |
|
BLAKE2b-256 | b06155618f395cb2d1e528021aed3d04784e1ebf388fbb1bcb371d6b3b396f9f |