两组字符串取交集、差集,并集

  • Post author:
  • Post category:其他


取交集
s = 'abcdef'
b = 'bced'
结果:{'c', 'e', 'd', 'b'}
f =(set(s)).intersection(set(b))
取并集
f =(set(s)).union(set(b))
结果:{'d', 'e', 'f', 'c', 'b', 'a'}
取差集
f =(set(s)).difference(set(b))
结果:{'a', 'f'}



版权声明:本文为weixin_43883907原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。