[issue30196] Add __matmul__ to collections.Counter

Jáchym Barvínek report at bugs.python.org
Fri Apr 28 06:19:20 EDT 2017


New submission from Jáchym Barvínek:

The class collections.Counter should semantically contain only numbers, so it makes sense to define dot product od Counters, something like this:

def __matmul__(self, other):
  return sum(self[x] * other[x] for x in self.keys() | other.keys())

I find this useful ocassionaly.

----------
components: Library (Lib)
messages: 292522
nosy: Jáchym Barvínek
priority: normal
severity: normal
status: open
title: Add __matmul__ to collections.Counter
type: enhancement
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30196>
_______________________________________


More information about the Python-bugs-list mailing list