人工智能,也就是python语言,是一种高级代码,在程序员的眼里,python就像胶水一样,他可以适应于各种情况,可以以最简单的代码去解决复杂的问题,现阶段python的使用率非常高,知乎就是以python代码编写的网站,而python也可以编写爬取sprider等非常方便的工具,今天达内小编为大家带来,python的基础,希望大家喜欢!
集合的交并差集
# 列表
li_one = [1, 2, 3, 4]
li_two = [1, 4, 5, 6]
# 列表转为set集合
set_one = set(li_one)
set_two = set(li_two)
# 求交集(两个集合公共的)
print(“intersection方法:”, set_one.intersection(set_two))
print(“&符号:”, set_one & set_two)
# 求并集(两个集合合并去重)
print(“union方法:”, set_one.union(set_two))
print(“|符号:”, set_one | set_two)
# 求差集(第一个集合减去第二个集合去除共有的剩下自己的和他有的)
print(“difference方法:”, set_one.difference(set_two))
print(“-符号:”, set_one - set_two)
达内告诉我们,python的代码都很短,更多精彩内容尽在达内