by @kodeazy
Python check given value exist in dictionary or not?
In this blog we will discuss on how to check if given value is present in a dictionary are not in python.
I have a dict
of names as below.
names={"1":"Rajesh","2":"lokesh"};
To check value
Rajesh
is present in the above dict
we iterate through each key and search for the value as shown in below example.
names={"1":"Rajesh","2":"lokesh"};
exist=False;
for name in names:
if(names[name]=="Rajesh"):
exist=True;
break;
if(exist==True):
print("Given Value exist in dictionary ");
else:
print("Given value does not exist in dictionary ");
Output:
Given Value exist in dictionary