PYTHON去除重复元素2

import numpy as np
import pandas as pd

#输入:两个列表;
#输出:去除重复元素的列表
#方法:将list转换为array,处理之后,转换回去!挺麻烦啊!

#方式1(瞎折腾)
list1 = [1,3,5,1,7,3,1,1]
list2 = [2,4,6,2,8,4,2,2]

list3 = list(zip(list1,list2))#先将列表压缩成压缩对象,再转换为list
list3_array = np.array(list3)#这个可以将list转换为array(数组)
print(list3_array)

a = np.array(list(set([tuple(t) for t in list3_array]))) #这个是转换为矩阵
b = a.tolist()  #array转换为list
print(b)

#方式2:去掉不就好了
c = list(set([tuple(t) for t in list3_array])) #这个返回列表,像是list(zip())之后的
print(c)
#结果:
[[1 2]
 [3 4]
 [5 6]
 [1 2]
 [7 8]
 [3 4]
 [1 2]
 [1 2]]
[[1, 2], [3, 4], [5, 6], [7, 8]]
[(1, 2), (3, 4), (5, 6), (7, 8)]

https://blog.csdn.net/CHIERYU/article/details/86594650 文章中,使用 array = np.asarray(list) 的方法将list转换为array,那么与 np.array(list) 有什么区别呢?

推荐大家去看这里:https://www.jianshu.com/p/a050fecd5a29

从这个博客得到的灵感(python-去除二维数组/二维列表中的重复行):https://blog.csdn.net/u012991043/article/details/81067207

我的这个list转array的方案来自于(Python中list转换array的一个问题):https://blog.csdn.net/dta0502/article/details/90215049