这实际上是这个问题的变体,但不是重复的:
Python反向/反转映射
给出这样的字典:
mydict= { 'a': ['b', 'c'], 'd': ['e', 'f'] }
怎么能反转这个字典得到:
inv_mydict = { 'b':'a', 'c':'a', 'e':'d', 'f':'d' }
请注意,值在每个键下唯一地跨越.
注意:我以前有语法map = ...和dict = ...提醒不使用map,dict因为它们是内置函数,请参阅下面的优秀评论和答案:)
map = ...
dict = ...
map
dict
python mapping dictionary inverse
dictionary ×1
inverse ×1
mapping ×1
python ×1