Python列表可以进行简单的统计,比如list的函数count()可以直接统计元素出现的次数。
mylist = [2,2,2,2,2,2,3,3,3,3] myset = set(mylist) for item in myset: print mylist.count(item), " of ", item, " in list"