I have an arbitrary (JSON-serializeable) structure which contains lists of dicts
which I don't know anything about in advance (e.g.size or keys).
Is there a way to bring this list of dicts
into a deterministic order (in order to compare them)?
I could think of turning a list of dicts into a list of 2-tuples which I can compare but I'm looking for a 'pythonic' solution..
Please note: I don't want to sort a list of dicts by any key I have to know in advance but I want to sort generic (JSON-serializeable) lists of dicts.
Another note: I don't just want to compare the dicts but I want to be able to serialize them. So I'm looking for a function reorder
which makes sure
json.dumps(reorder([{'a': 1}, {'b': 2}])) == json.dumps(reorder([{'b': 2}, {'a': 1}]))