mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
More doc tweaks.
This commit is contained in:
parent
c8b4ceceee
commit
94adc8e4b5
1 changed files with 12 additions and 15 deletions
|
@ -179,18 +179,15 @@ For example::
|
||||||
Counter objects have a dictionary interface except that they return a zero
|
Counter objects have a dictionary interface except that they return a zero
|
||||||
count for missing items instead of raising a :exc:`KeyError`::
|
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
|
>>> c['bacon'] # count of a missing element is zero
|
||||||
0
|
0
|
||||||
|
|
||||||
Setting a count to zero still leaves an element in the dictionary. Use
|
Setting a count to zero does not remove an element from a counter.
|
||||||
``del`` to remove it entirely:
|
Use ``del`` to remove it entirely:
|
||||||
|
|
||||||
>>> c = Counter(['arthur', 'gwain'])
|
>>> c['sausage'] = 0 # counter entry with a zero count
|
||||||
>>> c['arthur'] = 0 # set the count of 'arthur' to zero
|
>>> del c['sausage'] # del actually removes the entry
|
||||||
>>> 'arthur' in c # but 'arthur' is still in the counter
|
|
||||||
True
|
|
||||||
>>> del c['arthur'] # del will completely remove the entry
|
|
||||||
|
|
||||||
.. versionadded:: 2.7
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
@ -272,19 +269,19 @@ counts less than one::
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
|
* `Counter class <http://code.activestate.com/recipes/576611/>`_
|
||||||
|
adapted for Python 2.5 and an early `Bag recipe
|
||||||
|
<http://code.activestate.com/recipes/259174/>`_ for Python 2.4.
|
||||||
|
|
||||||
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
|
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
|
||||||
in Smalltalk.
|
in Smalltalk.
|
||||||
|
|
||||||
* A `Counter <http://code.activestate.com/recipes/576611/>`_ conformant
|
|
||||||
recipe for Python 2.5 and an early Python `Bag recipe
|
|
||||||
<http://code.activestate.com/recipes/259174/>`_ for Python 2.4.
|
|
||||||
|
|
||||||
* Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_\.
|
* Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_\.
|
||||||
|
|
||||||
* `C++ multisets <http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm>`_
|
* `C++ multisets <http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm>`_
|
||||||
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,
|
*Knuth, Donald. The Art of Computer Programming Volume II,
|
||||||
Section 4.6.3, Exercise 19*\.
|
Section 4.6.3, Exercise 19*\.
|
||||||
|
|
||||||
|
@ -292,7 +289,7 @@ counts less than one::
|
||||||
elements, see the :func:`combinations_with_replacement` function in the
|
elements, see the :func:`combinations_with_replacement` function in the
|
||||||
:ref:`itertools-recipes` for itertools::
|
: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
|
:class:`deque` objects
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue