diff options
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/collections.rst | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index ca2f116..1a09379 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -268,6 +268,11 @@ For example:: .. versionadded:: 3.1 + .. versionchanged:: 3.7 As a :class:`dict` subclass, :class:`Counter` + Inherited the capability to remember insertion order. Math operations + on *Counter* objects also preserve order. Results are ordered + according to when an element is first encountered in the left operand + and then by the order encountered in the right operand. Counter objects support three methods beyond those available for all dictionaries: @@ -275,8 +280,8 @@ For example:: .. method:: elements() Return an iterator over elements repeating each as many times as its - count. Elements are returned in arbitrary order. If an element's count - is less than one, :meth:`elements` will ignore it. + count. Elements are returned in the order first encountered. If an + element's count is less than one, :meth:`elements` will ignore it. >>> c = Counter(a=4, b=2, c=0, d=-2) >>> sorted(c.elements()) @@ -287,10 +292,10 @@ For example:: Return a list of the *n* most common elements and their counts from the most common to the least. If *n* is omitted or ``None``, :meth:`most_common` returns *all* elements in the counter. - Elements with equal counts are ordered arbitrarily: + Elements with equal counts are ordered in the order first encountered: - >>> Counter('abracadabra').most_common(3) # doctest: +SKIP - [('a', 5), ('r', 2), ('b', 2)] + >>> Counter('abracadabra').most_common(3) + [('a', 5), ('b', 2), ('r', 2)] .. method:: subtract([iterable-or-mapping]) |