@@ -271,7 +271,7 @@ For example::
271
271
.. versionadded :: 3.1
272
272
273
273
.. versionchanged :: 3.7 As a :class:`dict` subclass, :class:`Counter`
274
- Inherited the capability to remember insertion order. Math operations
274
+ inherited the capability to remember insertion order. Math operations
275
275
on *Counter * objects also preserve order. Results are ordered
276
276
according to when an element is first encountered in the left operand
277
277
and then by the order encountered in the right operand.
@@ -366,19 +366,26 @@ Several mathematical operations are provided for combining :class:`Counter`
366
366
objects to produce multisets (counters that have counts greater than zero).
367
367
Addition and subtraction combine counters by adding or subtracting the counts
368
368
of corresponding elements. Intersection and union return the minimum and
369
- maximum of corresponding counts. Each operation can accept inputs with signed
369
+ maximum of corresponding counts. Equality and inclusion compare
370
+ corresponding counts. Each operation can accept inputs with signed
370
371
counts, but the output will exclude results with counts of zero or less.
371
372
373
+ .. doctest ::
374
+
372
375
>>> c = Counter(a = 3 , b = 1 )
373
376
>>> d = Counter(a = 1 , b = 2 )
374
377
>>> c + d # add two counters together: c[x] + d[x]
375
378
Counter({'a': 4, 'b': 3})
376
379
>>> c - d # subtract (keeping only positive counts)
377
380
Counter({'a': 2})
378
- >>> c & d # intersection: min(c[x], d[x]) # doctest: +SKIP
381
+ >>> c & d # intersection: min(c[x], d[x])
379
382
Counter({'a': 1, 'b': 1})
380
383
>>> c | d # union: max(c[x], d[x])
381
384
Counter({'a': 3, 'b': 2})
385
+ >>> c == d # equality: c[x] == d[x]
386
+ False
387
+ >>> c <= d # inclusion: c[x] <= d[x]
388
+ False
382
389
383
390
Unary addition and subtraction are shortcuts for adding an empty counter
384
391
or subtracting from an empty counter.
0 commit comments