Home > Backend Development > Python Tutorial > How to compare the differences between array elements in Python

How to compare the differences between array elements in Python

巴扎黑
Release: 2017-08-18 13:35:08
Original
3120 people have browsed it

The following editor will bring you a Python method to compare the similarities and differences of the elements of two arrays. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

Get the intersection/union/difference of two arrays through set():


print set(a).intersection(set(b)) # 交集
print set(a).union(set(b)) # 并集
print set(a).difference(set(b)) # 差集,在a中但不在b中的元素
print set(b).difference(set(a)) # 差集,在b中但不在a中的元素
Copy after login

The above is the detailed content of How to compare the differences between array elements in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template