Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Shalabyelectronics/f15c8267d9d4a35f6656428731f1866f to your computer and use it in GitHub Desktop.
Save Shalabyelectronics/f15c8267d9d4a35f6656428731f1866f to your computer and use it in GitHub Desktop.
glossary = {
"fruits": ["Apple", "Orange", "Banana"],
"vegetables": ["Cucumber", "Lemon", "Tomato"],
"sweets": ["Mars", "Kitkat", "Galaxy"]
}
# This about invers dictionary values from list to become a keys and their keys became a values that refer to them
def invert_dict(d):
inverse = dict()
for key in d:
val_list = d[key]
for val in val_list:
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
print(inverse)
invert_dict(glossary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment