苏小测

导航

 

from collections import defaultdict,Counter

-------------1

dd=defaultdict(int)
for item in names:
  dd[item]+=1
for k,v in dd.iteritems():
  pass
-------------2

for item in set(names):
  a=names.count(item)
-------------3

c=Counter(names)
for k,v in dict(c).iteritems():
  pass

1、3差不多,2最慢

posted on 2022-01-08 09:56  苏小测  阅读(35)  评论(0编辑  收藏  举报