close
[python]word count / word frequency

有一個list
[a,b,c,a,b,b,a]
要成為
{'a':2,'b':3,'c:1'}


from collections import defaultdict
fq= defaultdict( int )
for w in words:
fq[w] += 1


-end-
arrow
arrow

    peicheng 發表在 痞客邦 留言(0) 人氣()