Counter
Introduction
Counter package defines the counter.Counter class similar to bags or multisets in other languages. This package is created from Raymond Hettinger recipe: http://code.activestate.com/recipes/576611/
Installation
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://github.com/KelSolaar/Counter.git python setup.py install
Usage
For precise usage examples, please refer to the original recipe: http://code.activestate.com/recipes/576611/ and Python documentation: http://docs.python.org/library/collections.html#collections.Counter
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})
About
Metadata
Release files for Counter 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Counter-1.0.0.tar.gz | 5.2 kB | Without provenance | Details for Counter-1.0.0.tar.gz |
Release files / Counter-1.0.0.tar.gz
| Download URL | Counter-1.0.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e008590e360936a66c98e1a01e7a9a0ecf6af19cc588107121f5fb4613bb60c
|
|
BLAKE2b-256 checksum How to use checksums |
7db023d19892f8d91ec9c5b8a2035659bce23587fed419d68fa3d70b6abf8bcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for Counter 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.