Module to use dictionaries in various situations
Project description
pydicts
Module to use dictionaries in various situations
Acronyms
pydicts uses several acronyms to call functions and parameters
- lod: List of dictionaries
[{"a":1,"b":2}, {"a":3,"b":4}]
- lood: List of ordered dictionaries (OrderedDicts from collections module)
[OrderedDict([('a', 1), ('b', 2)]), OrderedDict([('a', 3), ('b', 4)])]
- lol: List of lists
[[1, 2, 3], [4, 5, 6]]
- dod: Dictionary of dictionaries
{'key2': {'a': 1, 'b': 2}, 'key1': {'a': 1, 'b': 2}}
- lod_ymv: List of dictionaries with year-month-value keys
[{'year': 2021, 'month': 1, 'value': 12.12}, {'year': 2023, 'month': 3, 'value': 13.03}]
- lod_xyv: List of dictionaries with x-y-value keys
[{'X': 21, 'Y': 12, 'value': 180}, {'X': 2, 'Y': 122, 'value': 170}]
LOD
lod_has_key
Returns a boolean. Checks if list of dictionaries has a key
>>> from pydicts.lod import lod_has_key
>>> lod=[{"a":1, "b":4},{"a":2, "b":5}]
>>> lod_has_key(lod,"a")
True
>>> lod_has_key(lod,"d")
False
>>> lod_has_key([],"d")
False
lod_print
Prints a list of dictionaries in a tabulated way
>>> from pydicts.lod import lod_print
>>> lod=[{"a":1, "b":4},{"a":2, "b":None}]
>>> lod_print(lod)
+-----+-----+
| a | b |
|-----+-----|
| 1 | 4 |
| 2 | |
+-----+-----+
lod_sum
Sums all values from a lod key. None values are ignored by default
>>> from pydicts.lod import lod_sum
>>> lod=[{"a":1, "b":4},{"a":2, "b":None}]
>>> lod_sum(lod,"a")
3
>>> lod_sum(lod,"b")
4
>>> lod_sum(lod,"b",ignore_nones=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/keko/Proyectos/pydicts/pydicts/lod.py", line 46, in lod_sum
r=r+d[key]
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Testing
poetry run pytest
CHANGELOG
0.2.0 (2023-04-12)
- Added lod_print with tabulate module
- Improving documentation
- Refactorized modules to lod_xyv, lod_ymmv
0.1.0 (2023-04-10)
- First version addapting listdict_functions from reusingcode
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
pydicts-0.2.0.tar.gz
(18.7 kB
view details)
Built Distribution
pydicts-0.2.0-py3-none-any.whl
(19.9 kB
view details)
File details
Details for the file pydicts-0.2.0.tar.gz
.
File metadata
- Download URL: pydicts-0.2.0.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.2.9-gentoo
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 029fb5210218deb1c0911e6bfe55818249bdc30333c65a1295cd2b0d4e630b9f |
|
MD5 | 5c6b63264d9fef3a182d4b9ba438b2ad |
|
BLAKE2b-256 | da85012b5a4217148ab69a1c5c5d8dbfe01e83b9564fb5f8e3b9cfa1fa709edf |
Provenance
File details
Details for the file pydicts-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pydicts-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.11 Linux/6.2.9-gentoo
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dec3198014e9c2c84641d18d2a357d7f067933a4743383246c72c1db13abfc8 |
|
MD5 | a0faf8800c8d5f7ae7b991494bf595fd |
|
BLAKE2b-256 | f765290bb27da4098d345599f4f74300994e01121878523e28ebb797d2603a22 |