Python Set intersection() 方法
Python 3 教程
· 2019-02-06 19:13:06
描述
intersection() 方法用于返回两个或更多集合中都包含的元素,即交集。
语法
intersection() 方法语法:
set.intersection(set1, set2 ... etc)
参数
- set1 -- 必需,要查找相同元素的集合
- set2 -- 可选,其他要查找相同元素的集合,可以多个,多个使用逗号 , 隔开
返回值
返回一个新的集合。
实例
返回一个新集合,该集合的元素既包含在集合 x 又包含在集合 y 中:
实例 1
x = {"apple", "banana", "cherry"}
y = {"google", "codercto", "apple"}
z = x.intersection(y)
print(z)
输出结果为:
{'apple'}
计算多个集合的并集:
实例 1
x = {"a", "b", "c"}
y = {"c", "d", "e"}
z = {"f", "g", "c"}
result = x.intersection(y, z)
print(result)
输出结果为:
{'c'}
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
Spring Cloud微服务实战
翟永超 / 电子工业出版社 / 2017-5 / 89
《Spring Cloud微服务实战》从时下流行的微服务架构概念出发,详细介绍了Spring Cloud针对微服务架构中几大核心要素的解决方案和基础组件。对于各个组件的介绍,《Spring Cloud微服务实战》主要以示例与源码结合的方式来帮助读者更好地理解这些组件的使用方法以及运行原理。同时,在介绍的过程中,还包含了作者在实践中所遇到的一些问题和解决思路,可供读者在实践中作为参考。 《Sp......一起来看看 《Spring Cloud微服务实战》 这本书的介绍吧!