>>> d = { 'a': 1, 'b': 2, 'c': 3 }
>>> d.items()
[('a', 1), ('c', 3), ('b', 2)]
>>> [(v, k) for k, v in d.iteritems()]
[(1, 'a'), (3, 'c'), (2, 'b')]
It's not in the order you want, but dicts don't have any specific order anyway.1 Sort it or organize it as necessary.
See: items(), iteritems()
In Python 3.x, you would not use iteritems
(which no longer exists), but instead use items
, which now returns a "view" into the dictionary items. See the What's New document for Python 3.0, and the new documentation on views.
1: Insertion-order preservation for dicts was added in Python 3.7
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…