From 94adc8e4b54d6532dd8a4b265133d4105b96ea7a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 22 Jan 2009 05:27:37 +0000 Subject: [PATCH] More doc tweaks. --- Doc/library/collections.rst | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 4cf3a48b03f..803abab73ab 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -179,18 +179,15 @@ For example:: Counter objects have a dictionary interface except that they return a zero count for missing items instead of raising a :exc:`KeyError`:: - >>> c = Counter(['egg', 'ham']) + >>> c = Counter(['eggs', 'ham']) >>> c['bacon'] # count of a missing element is zero 0 - Setting a count to zero still leaves an element in the dictionary. Use - ``del`` to remove it entirely: + Setting a count to zero does not remove an element from a counter. + Use ``del`` to remove it entirely: - >>> c = Counter(['arthur', 'gwain']) - >>> c['arthur'] = 0 # set the count of 'arthur' to zero - >>> 'arthur' in c # but 'arthur' is still in the counter - True - >>> del c['arthur'] # del will completely remove the entry + >>> c['sausage'] = 0 # counter entry with a zero count + >>> del c['sausage'] # del actually removes the entry .. versionadded:: 2.7 @@ -272,19 +269,19 @@ counts less than one:: .. seealso:: + * `Counter class `_ + adapted for Python 2.5 and an early `Bag recipe + `_ for Python 2.4. + * `Bag class `_ in Smalltalk. - * A `Counter `_ conformant - recipe for Python 2.5 and an early Python `Bag recipe - `_ for Python 2.4. - * Wikipedia entry for `Multisets `_\. * `C++ multisets `_ - tutorial with standalone examples. + tutorial with examples. - * For use cases for multisets and mathematical operations on multisets, see + * For mathematical operations on multisets and their use cases, see *Knuth, Donald. The Art of Computer Programming Volume II, Section 4.6.3, Exercise 19*\. @@ -292,7 +289,7 @@ counts less than one:: elements, see the :func:`combinations_with_replacement` function in the :ref:`itertools-recipes` for itertools:: - map(Counter, combinations_with_replacement('abc', 2)) --> AA AB AC BB BC CC + map(Counter, combinations_with_replacement('ABC', 2)) --> AA AB AC BB BC CC :class:`deque` objects