List intersection
Returns a list of elements that exist in both lists.
- Create a
setfromaandb. - Use the built-in set operator
&to only keep values contained in both sets, then transform thesetback into alist.
Returns a list of elements that exist in both lists.
set from a and b.& to only keep values contained in both sets, then transform the set back into a list.