1. 程式人生 > >python去除重複元素,統計重複元素

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))