Simplify this condition

Question:

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')

How does this condition works => (a,b)!=(i,dict1[i])?
Also, what are the test scenarios we’ll get ‘no’ printed?

I tried running below test scenarios:
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

Asked By: Lipika Kandari

||

Answers:

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)  
Answered By: Deepak Tripathi

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.

Answered By: Claudio