[New-bugs-announce] [issue43171] Counter not supported add in Python 3.x

Frank AK report at bugs.python.org
Mon Feb 8 16:11:25 EST 2021


New submission from Frank AK <dropthemasquerade at gmail.com>:

In python 3.10, you couldn't plus two Counter instance, you will got the below tip:

```
>>> from collections import Counter
>>> x={1:['a','b','c']}
>>> y={1:['d','e','f'],2:['g']}
>>> Counter(y) + Counter(x)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/frank/github.com/cpython/Lib/collections/__init__.py", line 797, in __add__
    if newcount > 0:
TypeError: '>' not supported between instances of 'list' and 'int'
```

But in Python 2, you got the desire result like :

```
>>> from collections import Counter
>>> x={1:['a','b','c']}
>>> y={1:['d','e','f'],2:['g']}
>>> Counter(x) + Counter(y)
Counter({2: ['g'], 1: ['a', 'b', 'c', 'd', 'e', 'f']})
```

----------
messages: 386667
nosy: landpack
priority: normal
severity: normal
status: open
title: Counter not supported add in Python 3.x
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43171>
_______________________________________


More information about the New-bugs-announce mailing list