python去除重复元素,统计重复元素

test_labels_all = [1, 1, 2, 2, 2, 4, 6, 6]


## 去除重复数字
list1 = list(set(test_labels_all))  
print(list1)
--->[1, 2, 4, 6]


###统计重复数字出现个数

a = {}
for i in test_labels_all:
    a[i] = test_labels_all.count(i)
print(a)


#或者

set_one = set(test_labels_all)
for item in set_one:
    print(item, test_labels_all.count(item))

猜你喜欢

转载自blog.csdn.net/qq_38640439/article/details/82693569