Inverting a Python dictionary with zip(): swapping keys and values

Published: 13 September 2023
on channel: PatchyPython
73
0

The zip function transforms two lists of the same length into a single list by "pairing up" corresponding elements into a tuple. Here, we use "zip" to "invert" a dictionary, by swapping its keys for its values and vice-versa. Note that since all the keys in a dictionary must obviously be different, this makes sense only if no two values are equal.

For more information, see the notebooks below (notebooks will open on Google Colab - no installation required)

Embedded video, part of the following courses:
Computer Programming at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/3xjmpf94
Coding for Scientists at Queen Mary, University of London
Jupyter notebook: https://tinyurl.com/yedumefr


Watch video Inverting a Python dictionary with zip(): swapping keys and values online without registration, duration hours minute second in high quality. This video was added by user PatchyPython 13 September 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 73 once and liked it 0 people.