我需要通过另一个元素来确定顺序,对我的字典进行排序。
unsorted_dict = {'potato':'whatever1', 'tomato':'whatever2', 'sandwich':'whatever3'}
这种排序可以作为列表或字典呈现,取决于哪种更容易。
ordination = ['sandwich', 'potato', 'tomato']
排序后的字典:
sorted_dict = {'sandwich':'whatever3', 'potato':'whatever1', 'tomato':'whatever2'}