Collection Methods

collections.Counter.subtract()

Subtract counts from another iterable or mapping in place. Unlike multiset subtraction, zero and negative results are retained.

Formal Syntax & Structure

python syntaxpython
counter.subtract(iterable=None, /, **kwargs)

Parameters & Attributes

NameTypeDescription
iterableiterable or mapping or NoneIterable of elements or mapping of elements to counts; omitted or None means no positional input.
kwargsobjectAdditional keyword entries or arguments.

Return Value

None

No return value; the operation changes the receiver in place.

Working Example

Example Snippetpython
import collectionsc=collections.Counter(a=1,b=1)c.subtract("aa")print(dict(c))
Python Reference