x = set('asdfvcxwe');
y = set('cswew');
print x ,y
print 'x - y:'
print (x - y)
print 'x | y:'
print (x | y)
print 'x & y:'
print(x & y)
output
set(['a', 'c', 'e', 'd', 'f', 's', 'w', 'v', 'x']) set(['c', 'e', 's', 'w'])
x - y:
set(['a', 'x', 'v', 'd', 'f'])
x | y:
set(['a', 'c', 'e', 'd', 'f', 's', 'w', 'v', 'x'])
x & y:
set(['c', 'e', 's', 'w'])
本文通过一个简单的Python代码示例展示了如何使用集合进行基本的操作,包括求差集、并集及交集等,有助于理解集合在数据处理中的应用。

被折叠的 条评论
为什么被折叠?



