How to compare two lists and return matches in Python

2 Answers

0 votes
l1 = [1, 2, 3, 4]     
l2 = [1, 2, 3, 5]     

   
print(set(l1) & set(l2))     


     
'''
run:
 
{1, 2, 3}

'''

 



answered Apr 29, 2019 by avibootz
0 votes
l1 = [1, 2, 3, 4]     
l2 = [1, 2, 3, 5]     

print(set(l1).intersection(l2))     


     
'''
run:
 
{1, 2, 3}

'''

 



answered Apr 29, 2019 by avibootz
...