List intersection
Returns a list of elements that exist in both lists.
- Create a
set
froma
andb
. - Use the built-in set operator
&
to only keep values contained in both sets, then transform theset
back 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
.