I'm trying to build a matrix that will contains the values from a dictionary, I know dictionaries are unordered but I'd like to sort the values in the matrix (which can be sorted) in a certain order based off the key names in the dictionary.
Let's say I have a dictionary like so:
{'a': 1, 'b': 2, 'c': 3 }
And a list with the key names in the order that I'd like the data from the matrix to be arranged:
['b', 'c'. 'a']
How can I use the list above to sort the values from the dictonary in a way that gives me a list like so:
[2, 3, 1]
Without explicitly mentioning each key during list comprehension, like so:
data = [ data['b'], data['c'], data['a'] for data in dict ]
The dictionary that I'm pulling data from has many keys and I'd rather not use the above method to pull 10-15 data points from this dictionary.