Contact: aviboots(AT)netvision.net.il
41,578 questions
54,200 answers
573 users
list1 = [1, 2, 3, 4, 5] list2 = [6, 0, 2, 1, 7, 9] set1 = set(list1) set2 = set(list2) intersection = list(set1 & set2) print(intersection) ''' run: [1, 2] '''
list1 = [1, 2, 3, 4, 5] list2 = [6, 0, 2, 1, 7, 9] set1 = set(list1) set2 = set(list2) intersection = list(set(list1).intersection(list2)) print(intersection) ''' run: [1, 2] '''
list1 = [1, 2, 3, 4, 5] list2 = [6, 0, 2, 1, 7, 9] intersection = list(set(list1) & set(list2)) print(intersection) ''' run: [1, 2] '''
list1 = [1, 2, 3, 4, 5] list2 = [6, 0, 2, 1, 7, 9] intersection = [x for x in list1 if x in list2] print(intersection) ''' run: [1, 2] '''