List intersection, union, and difference

Get the intersection of two list

list(set(listA).intersection(set(listB)))

 

And get two sets of list

list(set(listA).union(set(listB)))

 

Get the difference between two sets of list

List (the SET (listB) .difference (the SET (listA))) # listB there but not in listA

 

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Guess you like

Origin www.cnblogs.com/shiliye/p/11592316.html