Similarly to this question and this question, I'd like to swap keys and values in a dictionary.
The difference is, my values are lists, not just single values.
Thus, I'd like to turn:
In [120]: swapdict = dict(foo=['a', 'b'], bar=['c', 'd'])
In [121]: swapdict
Out[121]: {'bar': ['c', 'd'], 'foo': ['a', 'b']}
into:
{'a': 'foo', 'b': 'foo', 'c': 'bar', 'd': 'bar'}
Let's assume I'm happy that my values are unique.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…