I have a large dictionary of which I want to sort the list values based on one list. For a simple dictionary I would do it like this:
d = {'a': [2, 3, 1], 'b': [103, 101, 102]}
d['a'], d['b'] = [list(i) for i in zip(*sorted(zip(d['a'], d['b'])))]
print(d)
Output:
{'a': [1, 2, 3], 'b': [102, 103, 101]}
My actual dictionary has many keys with list values, so unpacking the zip tuple like above becomes unpractical. Is there any way to do the go over the keys and values without specifying them all? Something like:
d.values() = [list(i) for i in zip(*sorted(zip(d.values())))]
Using d.values() results in SyntaxError: can't assign function call, but I'm looking for something like this.