pysnippets.dicts
Inverting, searching, mapping and sorting mappings.
- collect_dictionary(d)Invert a dict so each value maps to the list of keys that had it.
- find_keys(d, value)Return every key whose value equals a given value.
- get_nested(data, path, default)Follow a path of keys and indexes through nested dicts and lists, with a default.
- invert_dictionary(d)Swap keys and values with a dict comprehension; the last key wins on shared values.
- key_of_max(d) +1Find the key with the largest or smallest value using max() or min() with a key function.
- map_values(d, fn)Build a new dict with a function applied to each value, keeping the keys.
- pluck(records, key)Collect the value of a key from each dict, with None where it's missing.
- sort_dict_by_value(d, *, reverse)Return a copy of a dict ordered by its values, ascending or descending.