I'm trying to sort the values of a dictionary in ascending order by the key, but the problem is that these values have two items in the key and I'm only trying to sort it by the second key item. If that makes any sense.
For example:
{[keyitem1],[keyitem2]:[Value]}
I'm trying to sort it by keyitem2
I tried sorting it by sorting it by their keys
Attempt #1
order = dict(sorted(mylist.keys()))
#1 outputs a ValueError:
ValueError: dictionary update sequence element #0 has length 54; 2 is required
Attempt #2
order = sorted(my_dict, key=operator.itemgetter(1))
#2 doesn't actually sort it, it's just randomised
Expected output
my_dict = {"('first', [0.011])": [1], "('second', [0.012])": [2], "('third', [0.013])": [3], "('fourth', [0.014])": [4], }
Actual output
my_dict = {"('second', [0.012])": [2], "('fourth', [0.014])": [4], "('first', [0.011])": [1], "('third', [0.013])": [3]}