Question;
With two given lists ([6,5,6,2,2]) and ([9,5,6,7,9,2,7,0]), write a python program to make a list whose elements are intersection of the another list.
Program:
1 2 3 4 5 |
set1=set([6,5,6,2,2]) set2=set([9,5,6,7,9,2,7,0]) set1 &= set2 li=list(set1) print (li) |
Explanation:
Use set() and “&=” to do set intersection operation.
Output:
1 |
[2, 5, 6] |
Leave a Reply