码迷,mamicode.com
首页 > 其他好文 > 详细

017_set

时间:2018-09-04 23:32:50      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:amp   int   enc   auth   list   car   author   add   and   

#!/usr/bin/env python
# Author:liujun

list1 = [1,4,5,7,3,6,7,9]
list1 = set(list1)
# set is unordered

list2 = set([2,6,0,66,22,8,4])
print(list1.intersection(list2))
print(list1 & list2)
# Extract the intersection of the two lists

print(list1.union(list2))
print(list2 | list1)
# Extract the union of the two lists

print(list1.difference(list2))
print(list1 - list2)
# Extract the difference of the two lists

print(list1.issubset(list2))
# Determine whether a list is a sutset of another

print(list1.issuperset(list2))
# Determine whether a list is a parent of another

print(list1.symmetric_difference(list2))
print(list1 ^ list2)
# Extract symmetric_difference of the two lists


list1.add(555)
# Add single element

list1.update([55,66,88,99])
# Add multiple elements


list1.pop()
# Return and remove an arbitrary set element
list1.discard(888)
# Remove the element


print(list1)

017_set

标签:amp   int   enc   auth   list   car   author   add   and   

原文地址:https://www.cnblogs.com/liujun5319/p/9588956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!