python1.3集合知识点:
2020-12-13 04:15
标签:没有 转换 amp value print 重复 集合 运算 set #定义集合:{},集合是只有key没有value的字典,集合内元素不能重复! #集合对列表进行去重 #集合运算 python1.3集合知识点: 标签:没有 转换 amp value print 重复 集合 运算 set 原文地址:https://www.cnblogs.com/lma0702/p/11106277.html
a={1,2,3,4,5,6}
#列表转换成集合
b=set([1,2,3,4,5])
print(a,b)
list1=[1,1,2,2,3,4,5,6,7,8]
#转换成集合
x=set(list1)
#还原成列表
y=list(x)
print(y)
c={1,2,3,4,5,6,7}
d={4,5,6,7,8,9,0}
#集合差(在C集合中去掉共有元素)
print(c-d)
#集合并(合并两集合的所有元素)
print(c|d)
#集合交(提取两集合的共同元素)
print(c&d)
#集合对称差(去掉两集合相同的元素然后合并)
print(c^d)
上一篇:Winrar大全