How to find the value of bool

Solution 1:

The fastest way is to transform both in sets and print the difference:

>>> print(set(x).difference(set(y)))
{6}

This code print numbers present in x but not in y

Solution 2:

You can do like this:

x = [1,2,3,4,5,6]
y = [1,2,3,4,5]

for i in x:
    if i not in y:
        print(i)

Solution 3:

x =[1,2,3,4,5,6]
y = [1,2,3,4,5]

for i in x:
    if i in y:
        print(f"{i} found")
    else:
        print(f"{i} not found")

Solution 4:

This is the best option in my opinion.

x =[1,2,3,4,5,6]
y = [1,2,3,4,5]

for number in x:
    if number not in y:
        print(f"{number} not found")

Solution 5:

to get not matches:

def returnNotMatches(a, b):
    return [[x for x in a if x not in b], [x for x in b if x not in a]]

or

new_list = list(set(list1).difference(list2))

to get the intersection:

list1 =[1,2,3,4,5,6]
list2 = [1,2,3,4,5]
list1_as_set = set(list1)
intersection = list1_as_set.intersection(list2)

output:

{1, 2, 3, 4, 5}

you can also transfer it to a list:

intersection_as_list = list(intersection)

or:

new_list = list(set(list1).intersection(list2))