【发布时间】:2014-02-16 02:22:45
【问题描述】:
我试图弄清楚如何获取每个项目中有多少在一个字符串中。比如:
{"harley": ["apple", "apple", "banana"]}
那我怎么得到这个:
Harley has Apple x 2 and Banana x 1
【问题讨论】:
-
列表也有
count的方法,但是如果你想把所有的东西都统计一遍,效率会低很多。 -
嗯。看起来像 collections.Counter 很适合这个。
标签: python