How to use 'reverse a dictionary python' in Python

Every line of 'reverse a dictionary python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
12def reverseDictionary(dictionary):
13 """
14 Reverses a dictionary so that the keys become the values. Mainly
15 so that the existing dictionaries for decompiling the TI-Basic files
16 can be used here as well.
17
18 Arguments:
19 dictionary (dict): a dictionary to flip
20 Returns:
21 flipped (dict): a dictionary with the key/value pairs reversed
22 """
23 flipped = dict()
24 for key in dictionary:
25 flipped[dictionary[key].strip()] = key
26
27 return flipped
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets