How to use sets to find intersection in python
This article is about how python uses collections to find intersections. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Use sets to find intersection
Replace the following code:
A = [1, overlaps 2, 3, 4, 5, 5] b = [2, 3, 4, 5, 5] for x in a = [] for x in a: for y in b: if Xerox: overlaps.append (x) print (overlaps)
Change to set and intersection:
Overlaps = set (a) & set (b) print (overlaps) Thank you for reading! This is the end of this article on "how python uses sets to intersect". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!