counts = bounter(size_mb=1024) # use at most 1 GB of RAM counts.update([u'a', 'few', u'words', u'a', u'few', u'times']) # count item frequencies
print(counts[u'few']) # query the counts 2
示例二
from bounter import bounter
counts = bounter(size_mb=200) # default version, unless you specify need_items or need_counts counts.update(['a', 'b', 'c', 'a', 'b']) print(counts.total(), counts.cardinality()) # total and cardinality still work (5L, 3) print(counts['a']) # individual item frequency still works 2
print(list(counts)) # iterator returns keys, just like Counter [u'b', u'a', u'c'] print(list(counts.iteritems())) # supports iterating over key-count pairs, etc. [(u'b', 2L), (u'a', 2L), (u'c', 1L)]