代碼部分:
In [26]: a = {1:"a",2:"b"}
In [27]: a
Out[27]: {1: 'a', 2: 'b'}
In [28]: list(a.keys())[list(a.values()).index('a')]
Out[28]: 1
引用一段Python3文檔里面的原話。
If keys, values and items views are iterated over with no intervening modifications to the dictionary, the order of items will directly correspond.
也就是說,在你迭代的過程中如果沒有發生對字典的修改,那么.keys() and .values 這兩個函數返回的 dict-view對象總是保持對應關系