标签:关系 sha his 运算 enc 集合 bsp col inter
1.交集
r = ["hehe","haha","woaini"] v = ["hehe","haha","nishishabi"] p = set(r) y = set(v) print(p.intersection(y)) print(p&y) {‘hehe‘, ‘haha‘} {‘hehe‘, ‘haha‘}
用intersection或者&都可以
2.并集
r = ["hehe","haha","woaini"] v = ["hehe","haha","nishishabi"] p = set(r) y = set(v) print(p.union(y)) print(p|y) {‘haha‘, ‘hehe‘, ‘woaini‘, ‘nishishabi‘} {‘haha‘, ‘hehe‘, ‘woaini‘, ‘nishishabi‘}
用union或者|都可以
3.差集
r = ["hehe","haha","woaini"] v = ["hehe","haha","nishishabi"] p = set(r) y = set(v) print(p-y) print(p.difference(y)) {‘woaini‘} {‘woaini‘}
用difference或者-都可以
标签:关系 sha his 运算 enc 集合 bsp col inter
原文地址:https://www.cnblogs.com/newt/p/8986715.html