A python dictionary with rather loose rules for finding elements
MIT License
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.
pip install permissive-dict
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.
Example:
a = PermissiveDict()
a.hello = 4
a.hello == a['hello'] == a('hello') == a.get('HellO')
An entire list of dictionaries can be converted to PermissiveDict using
the convert_list
method. NOTE: no deep conversion is done and child
dictionaries are not converted.
Example:
list_of_dicts = [dict(a=n) for n in range(10)]
permissive_list = PermissiveDict.convert_list(list_of_dicts)
Only Python 3 is supported.
1.0.4 Fix missing handling of _ and -