a = [34,56,23,68]
b = [76,78324,1234]
dict1 = {34:76,56:1234}
for i in dict1:
if (a,b)!=(i,dict1[i]):
print('yes')
else:
print('no')
What does this condition check =>
(a,b)!=(i,dict1[i])
? Also, what are the conditions when we will get no as result?
- If key and value present in
dict1
match with a and b list- O/p : yes yes - If key match and value does not it gives - O/p : yes yes
- If key and value does not match it gives - O/p : yes yes
CodePudding user response:
Here an answer to the question instead of suggestions what the condition is actually supposed to be given in the other answers:
How does this condition work => (a,b)!=(i,dict1[i])
?
This condition compares a tuple of two lists a
and b
with a tuple of two integers being key and value in dict1
and will be always True
because a list is not equal to an integer.
Also, what are the test scenarios we'll get 'no' printed?
With the understanding of the way the condition works described above you see that there are no test scenarios in which 'no' will be printed.
CodePudding user response:
Try with zip
for ordered and product
for all combinations
from itertools import product
a = [34,56,23,68]
b = [76,78324,1234]
dict1 = {34:76,56:1234}
# if you want to check in ordered manner that is first elemet of a and first element of b then you can use
for i,j in zip(a,b):
if i in dict1 and dict1[i]==j:
print("yes", i, j)
# if you want to check the combination of a and b in dict1 then you can try
for i,j in product(a,b):
if i in dict1 and dict1[i]==j:
print("yes", i, j)