Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use sets to find intersection in python

Shulou Source: shulou.com Published: 2022-06-01 06:12:34 09月30日 Update

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!

Tags: Intersection content more articles good practical code articles read knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Docker OPPO Reno Shulou Technology