This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort_recursive(node, first_keys, last_keys): | |
""" Sort the dictionary entries in a whole JSON object tree""" | |
fixed_placements = { | |
**{key: (0, idx) for idx, key in enumerate(first_keys)}, | |
**{key: (2, idx) for idx, key in enumerate(last_keys)}, | |
} | |
return _sort_recursive(node, lambda key: fixed_placements.get(key, (1, key))) | |
def _sort_recursive(node, key_fn): |