You can use a dictionary comprehension and the .items()
method.
In []: {k: oldk for oldk, oldv in swapdict.items() for k in oldv}
Out[]: {'a': 'foo', 'b': 'foo', 'c': 'bar', 'd': 'bar'}
More Related Contents:
- How can I calculate a list modulo a numer in python?
- How to remove English words from a file containing Dari words?
- How can I read inputs as numbers?
- Zip lists in Python
- Why is a list comprehension so much faster than appending to a list?
- Why is parenthesis in print voluntary in Python 2.7?
- python filter list of dictionaries based on key value
- Implement MATLAB’s im2col ‘sliding’ in Python
- How to convert a string to utf-8 in Python
- Selenium – MoveTargetOutOfBoundsException with Firefox
- Strip spaces/tabs/newlines – python
- importing a module when the module name is in a variable [duplicate]
- Is it safe to use the python word “type” in my code?
- OverflowError Python int too large to convert to C long
- Test if an internet connection is present in python
- class method generates “TypeError: … got multiple values for keyword argument …”
- How to locate and insert a value in a text box (input) using Python Selenium?
- Multiple keys per value
- flatten list of list through list comprehension
- Python Pandas – Read csv file containing multiple tables
- PyQt GUI order of operations
- Win32api is not giving the correct coordinates with GetCursorPos() in python
- Can’t install pygame on mac
- How to create a new text file using Python
- How to save python screen output to a text file
- Python: How to resize an image using PIL module
- Python not able to open file with non-english characters in path
- numpy.sum() giving strange results on large arrays
- How to fix TypeError: ‘int’ object is not subscriptable
- ‘is’ operator behaves unexpectedly with floats