方法一:使用for循环判断。
1 alist = ['apple','banana','apple','orange','orange','apple','apple','grape','banana','apple'] 2 3 new_count = {} 4 for n in alist: 5 if n not in new_count: 6 new_count[n] = 1 7 else: 8 new_count[n] += 1 9 10 #print(new_count) 11 for key,value in new_count.items(): 12 print(str(key) + ":" + str(value))