Dictionary with loose rules for finding keys.
Project description
PermissiveDict
Dictionary class with loose rules for returning an attribute or a requested key value.
Note: may resort to iterating the dict values to find the matching requested key, so is potentially slow.
Key is first directly found using the exact key, and then loose rules are used.
Key Search Rules:
- Keys compared without regard to case.
- Spaces, underscores, full-stops and dashes are equivalent in a requested key.
- Requested key is converted to str and stripped for wild card searching.
- Items in the list can be retrieved by, get, attribute_access, call or array requested_key.
- First matching element is returned.
- Default of '' is used instead of dict standard None or raising KeyError
- Multiple keys can be supplied separated with , (comma)
Example:
from permissive_dict import PermissiveDict
a = PermissiveDict({'A B': 2, 4: 4})
a.get('A_b') == a['a_b'] == a['A b'] == a['A_B'] == a['a-b '] == a['a.b '] == a.a_b == a.A_b == a('a-b')
a.get('blue,4') == 4
a.get('4') == a[4] == a(4) == a('4')
Items with multiple wildcard keys matching in the dictionary will return the first item found.
Keys can be accessed as attributes, array index, get() or by calling the instance variable.
Key and value can be set as an attribute.
Example:
a = PermissiveDict({'A B': 2, 4: 4})
a.hello = 4
a.hello == a['hello'] == a('hello') == a.get('HellO')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for permissive_dict-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb971a358398b60ede05e8630e79186aec314f60c2ef8e7235dc91d1ecc7c5ff |
|
MD5 | 13fc9b9beb013d46d427aa030a6689af |
|
BLAKE2b-256 | c18f232e076e4b0ad8f4cdb6e21afe187632a4168233ec9d791e63dc03ba05c5 |