Zihao

Make small but daily progress

0%

Python两个list比较去除重复元素,然后合并

方法一

1
2
3
4
5
6
7
8
9
>>> a = [1,3,5,7]
>>> b = [1,3,4,6,8]
>>> c = list(set(a+b))
>>> a
[1, 3, 5, 7]
>>> b
[1, 3, 4, 6, 8]
>>> c
[1, 3, 4, 5, 6, 7, 8]

方法二

1
2
3
a = [1,3,5,7]
b = [1,3,4,6,8]
c = list(set(a) | set(b))

方法三

1
2
3
a = [1,3,5,7]
b = [1,3,4,6,8]
c=list(set(a).union(set(b)))

欢迎关注我的其它发布渠道