1、
print set([1,2,3,4,5,5,6])
结果:
>>>
set([1, 2, 3, 4, 5, 6]) ####散列结构,无重复值;set函数有去重的功效;
2、
set1 =set([1,2,3,4,4])
set2 =set([2,3,4,5,6])
print set1-set2 ##set1有set2没有
print set1&set2 ##set1和set2都有的,交集
print set1|set2 ##set1和set2的并集;
结果:
>>>
set([1])
set([2, 3, 4])
set([1, 2, 3, 4, 5, 6])
>>>
阅读(999) | 评论(0) | 转发(0) |