-1

for example: a = {1:'hello' , 2:'bye'}

suppose I want to delete the element 2:'bye' through its value 'bye' , so can anyone help me by giving a piece of code.

thank you

Harmaan
  • 25
  • 5
  • What do you mean "through it's value"? You mean that all you have is the value? Well, then you have to find the key corresponding to that value. This will be a linear time operation (unless you create a reverse mapping, which of course, will require more memory). – juanpa.arrivillaga Nov 03 '20 at 09:50
  • 1
    Does this answer your question? [Removing entries from a dictionary based on values](https://stackoverflow.com/questions/15158599/removing-entries-from-a-dictionary-based-on-values) – Tom Wojcik Nov 03 '20 at 09:52

1 Answers1

0

for what I know you can do it like this

for i in a: # the dictionary
 if a[i] == 'bye':
   del a[i]

Hopefully this helps