summaryrefslogtreecommitdiffstats
path: root/Doc/library/collections.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-04 11:31:30 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-02-04 11:31:30 (GMT)
commit939a3cc5a2aa849d4876a5f42ffb2629d628f9bf (patch)
treedd74a91477c51b014cd23c4ca129d9ed5ecee96c /Doc/library/collections.rst
parent8184f5a46c740d637a44c4e01977ef7fdae54705 (diff)
downloadcpython-939a3cc5a2aa849d4876a5f42ffb2629d628f9bf.zip
cpython-939a3cc5a2aa849d4876a5f42ffb2629d628f9bf.tar.gz
cpython-939a3cc5a2aa849d4876a5f42ffb2629d628f9bf.tar.bz2
Tweak the docs for Counter() objects.
Diffstat (limited to 'Doc/library/collections.rst')
-rw-r--r--Doc/library/collections.rst8
1 files changed, 4 insertions, 4 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 22f41f9..6aaeb13 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -156,14 +156,14 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
A counter tool is provided to support convenient and rapid tallies.
For example::
- # Tally occurrences of words in a list
+ >>> # 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
+ >>> # Find the ten most common words in Hamlet
>>> import re
>>> words = re.findall('\w+', open('hamlet.txt').read().lower())
>>> Counter(words).most_common(10)
@@ -256,8 +256,8 @@ Several multiset mathematical operations are provided for combining
contain repeated elements (with counts of one or more). Addition and
subtraction combine counters by adding or subtracting the counts of
corresponding elements. Intersection and union return the minimum and maximum
-of corresponding counts. All four multiset operations exclude results with
-counts less than one::
+of corresponding counts. Each operation can accept inputs with signed counts,
+but the output excludes results with counts less than one.
>>> c = Counter(a=3, b=1)
>>> d = Counter(a=1, b=2)