问题
Python 2.7/3.1 introduced the awesome collections.Counter
.
My question: How do I count how many "element appearances" a counter has?
I want this:
len(list(counter.elements()))
But shorter.
回答1:
sum(counter.itervalues())
来源:https://stackoverflow.com/questions/5506359/checking-number-of-elements-in-pythons-counter