Say I have a dictionary and then I have a list that contains the dictionary\'s keys. Is there a way to sort the list based off of the dictionaries values?
I have bee
Yes dict.get is the correct (or at least, the simplest) way:
sorted(trial_list, key=trial_dict.get)
As Mark Amery commented, the equivalent explicit lambda:
sorted(trial_list, key=lambda x: trial_dict[x])
might be better, for at least two reasons: