I have a dictionary like below, as you see I am trying to print key_p
which is not in dictionary. I want to check if my key_p
exist in dictionary, print the value and when the key_p
is not in dictionary print 0
.
when I put condition elif
, it will print two times 0
( = the number of element in the dictionary) but I just want to check only key_p
, meaning if the key_p
is in the dictionary print 1
if only key_p
is not in the dictionary print 0
.
sc={'sen': 1,'lag': 1 }
key_p="tep"
for field, values in sc.items():
if field==key_p:
print("1")
elif field!=key_p:
print ("0")