Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,106 questions

40,778 answers

573 users

How to compare two lists in python and return the matches (common elements) in Python

Learn & Practice SQL


123 views
asked Nov 4, 2017 by avibootz
edited Nov 4, 2017 by avibootz

2 Answers

0 votes
l1 = [1, 2, 3, 4, 5]
l2 = [6, 7, 8, 9, 5, 4]

r = set(l1) & set(l2)

print(r)


'''
run:

{4, 5}

'''

 





answered Nov 4, 2017 by avibootz
0 votes
l1 = [1, 2, 3, 4, 5]
l2 = [6, 7, 8, 9, 5, 4]

result = set(l1).intersection(l2)

for n in result:
    print(n, end=" ")


'''
run:

4 5

'''

 





answered Nov 4, 2017 by avibootz

Related questions

2 answers 80 views
3 answers 90 views
2 answers 114 views
5 answers 195 views
...