This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description


Counter package defines the counter.Counter class similar to bags or multisets in other languages. This package is created from Raymond Hettinger recipe:


To install Foundations from the Python Package Index you can issue this command in a shell:

pip install Counter

or this alternative command:

easy_install Counter

Alternatively, if you want to directly install from Github source repository:

git clone git://
python install


For precise usage examples, please refer to the original recipe: and Python documentation:

  • Tally occurrences of words in a list:

    >>> cnt = Counter()
    >>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
    ...     cnt[word] += 1
    >>> cnt
    Counter({'blue': 3, 'red': 2, 'green': 1})
  • Find the ten most common words in Hamlet:

    >>> import re
    >>> words = re.findall('\w+', open('hamlet.txt').read().lower())
    >>> Counter(hamlet_words).most_common(10)
    [('the', 1143), ('and', 966), ('to', 762), ('of', 669), ('i', 631),
     ('you', 554),  ('a', 546), ('my', 514), ('hamlet', 471), ('in', 451)]
  • Multiset examples:

    >>> c = Counter(a=3, b=1)
    >>> d = Counter(a=1, b=2)
    >>> c + d                           # add two counters together:  c[x] + d[x]
    Counter({'a': 4, 'b': 3})
    >>> c - d                           # subtract (keeping only positive counts)
    Counter({'a': 2})
    >>> c & d                           # intersection:  min(c[x], d[x])
    Counter({'a': 1, 'b': 1})
    >>> c | d                           # union:  max(c[x], d[x])
    Counter({'a': 3, 'b': 2})


Counter by Raymond Hettinger – 2009
Copyright© 2009 - Raymond Hettinger
This software is released under terms of MIT license:
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Counter-1.0.0.tar.gz (5.2 kB) Copy SHA256 Checksum SHA256 Source Sep 19, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting