python 列表和集合相关操作

0x00

list 和 set 相关操作?

0x01

  • 列表去重
1
2
a = [1,2,3,3]
list = list(set(a))
  • 集合的运算
1
2
3
4
5
6
a = {1,2,3,3}
b = {3,4,5}
#交集 {3}
a.intersection(b)
#并集 {1, 2, 3, 4, 5}
a.union(b)
Author: ronething
Link: https://blog.ronething.cn/20190318-list-set.html
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.