[Solved] Comparing 2 lists without using “in”


>>>l1 = [i for i in range(1,25)]
>>>l2 = [i for i in range(24, 50)]
>>>[x for x in l1 if x in l2]
[24]

Sorry I misread. How about this:

for i in range(len(l1)):
    for j in range(len(l2)):
        if l2[j] == l1[i]:
            print l2[j]

If you need to add matches to a list just create a list outside of the loop and append.

0

solved Comparing 2 lists without using “in”