0

How do I reverse the order of key-value pairs of a dictionary, in Python? For example, I have this dictionary:

english_spanish = {"hi": "hola", "thanks": "gracias", "yes": "si", "no": "no"}

I want to reverse it so that it returns:

english_spanish = {"hola": "hi", "gracias": "thanks", "si": "yes", "no": "no"}

I would like to know how can you do it using the lampdabut i dont seem to understand how it works

OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Teemu
  • 49
  • 4

1 Answers1

-1
english_spanish = {"hi": "hola", "thanks": "gracias", "yes": "si", "no": "no"}
spanish_english = {v:k for (k, v) in english_spanish.items()}
print(spanish_english)
# {'hola': 'hi', 'no': 'no', 'gracias': 'thanks', 'si': 'yes'}
Prasad
  • 5,683
  • 3
  • 28
  • 36