Python reverse dictionary items order
问题 Assume I have a dictionary: d = {3: 'three', 2: 'two', 1: 'one'} I want to rearrange the order of this dictionary so that the dictionary is: d = {1: 'one', 2: 'two', 3: 'three'} I was thinking something like the reverse() function for lists, but that did not work. Thanks in advance for your answers! 回答1: Since Python 3.8 and above, the items view is iterable in reverse, so you can just do: d = dict(reversed(d.items())) On 3.7 and 3.6, they hadn't gotten around to implementing __reversed__ on