Dicts
- Dictionary Utils
dict_first(d)
Extract the first key, value pair from a dictionary. @param d: Dictionary to retrieve first key, value pair from. @return: Tuple containing key, value.
Source code in src/utils/dicts.py
66 67 68 69 70 71 72 |
|
dict_last(d)
Extract the last key, value pair from a dictionary. @param d: Dictionary to retrieve last key, value pair from. @return: Tuple containing key, value.
Source code in src/utils/dicts.py
75 76 77 78 79 80 81 |
|
dict_sort_by_key(d, reverse=False)
Sort a dictionary by its key. @param d: Dictionary to sort by its key. @param reverse: Whether to reverse the sorting order. @return: Key sorted dictionary.
Source code in src/utils/dicts.py
41 42 43 44 45 46 47 48 |
|
dict_sort_by_val(d, reverse=False)
Sort a dictionary by its value. @param d: Dictionary to sort by its value. @param reverse: Whether to reverse the sorting order. @return: Value sorted dictionary.
Source code in src/utils/dicts.py
51 52 53 54 55 56 57 58 |
|
reverse_dict(d)
Flips the key, val in a dictionary to val, key. @param d: Dictionary where the values are hashable. @return: Reversed dictionary.
Source code in src/utils/dicts.py
11 12 13 14 15 16 17 18 19 20 |
|
reverse_dict_safe(d)
Flips the key, val in a dictionary to val, [keys], preserving cases where the same value is mapped to multiple keys. @param d: Dictionary where the values are hashable. @return: Reversed dictionary.
Source code in src/utils/dicts.py
23 24 25 26 27 28 29 30 31 32 33 |
|