计数用的函数是count(),列表中会出现重复的项,所以转化成set去除重复元素
import numpy as np
list1 = [1,2,3,1,1,2,2,1,3]
list2 = list(set(list1))
for i in list2:
print(i,": ",list1.count(i))
计数用的函数是count(),列表中会出现重复的项,所以转化成set去除重复元素
import numpy as np
list1 = [1,2,3,1,1,2,2,1,3]
list2 = list(set(list1))
for i in list2:
print(i,": ",list1.count(i))