sliceable-dict
A simple dictionary that support slicing and multiple key selection.
Installation and requirements
sliceable-dict requires Python 3.7+ to run and can be installed by running
pip install sliceable-dict
Usage
The provided class SliceDict is an extended dictionary. It behaves exactly as the
buildin dict for single (hashable) keys, but adds some additional features.
Namely, getting and setting multiple keys at once, slicing with integers and boolean
selection.
An example usage:
>>> from sliceable_dict import SliceDict
>>> d = SliceDict(zero=0, one=1)
>>> d
{'zero': 0, 'one': 1,}
# multi-key support
>>> d[['two', 'three']] = 2, 3
>>> d[['one', 'three']]
{'one': 1, 'three': 3}
# slicing
>>> d[:]
{'zero': 0, 'one': 1, 'two': 2, 'three': 3}
>>> d[1:-1]
{'one': 1, 'two': 2}
>>> d[1::2]
{'one': 1, 'three': 3}
# boolean selection
>>> bool_list = [True, False, True, False]
>>> selection = d[bool_list]
>>> selection
{'zero': 0, 'two': 2}
# views as for buildin dict
>>> kv = selection.keys()
>>> kv
KeysView({'zero': 0, 'two': 2})
>>> list(kv)
['zero', 'two']
>>> vv = selection.values()
>>> vv
ValuesView({'zero': 0, 'two': 2})
>>> list(vv)
[0, 2]
Metadata
Release files for sliceable-dict 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sliceable_dict-0.4.1.tar.gz | 20.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sliceable_dict-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.6 kB
Release files / sliceable_dict-0.4.1.tar.gz
| Download URL | sliceable_dict-0.4.1.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b70465c66a857418b5b01f8d7a4492ccc278cba5d994ecb7a37a42994639f83
|
|
BLAKE2b-256 checksum How to use checksums |
e9e779d3fedda50d9dc94f46d08d9f8b03d3d5f50f493e61c4aa85be4039f572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / sliceable_dict-0.4.1-py3-none-any.whl
| Download URL | sliceable_dict-0.4.1-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c2e4058153b55f53001670d3b50784c66474557bf5d6004658df303291afe27
|
|
BLAKE2b-256 checksum How to use checksums |
569ecd5093b21367486a6dce772f4283bcaa2d1dc1670ec7de10ed216ceca284
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|