Logo

Programming-Idioms

History of Idiom 218 > diff from v13 to v14

Edit summary for version 14 by laowantong:
[Python] the argument of intersection() can be any iterable. This avoid converting b into a set prior to the intersection.

Version 13

2020-04-30, 20:18:12

Version 14

2020-05-02, 19:23:14

Idiom #218 List intersection

Create list c containing all unique elements that are contained in both lists a and b.
c should not contain any duplicates, even if a and b do.
The order of c doesn't matter.

Idiom #218 List intersection

Create list c containing all unique elements that are contained in both lists a and b.
c should not contain any duplicates, even if a and b do.
The order of c doesn't matter.

Extra Keywords
intersect and conjunction
Extra Keywords
intersect and conjunction
Code
c = list(set(a) & set(b))
Code
c = list(set(a).intersection(b))