Python empty counter comparison -


Does anyone know why the following is incorrect not true ? Are the counters not counted as a multiset? Any reference to the docs reception

  counter () == counter ({'a': 0})  

From:

Note : To represent the number of counters running primarily to work with positive integers was designed; However, matters requiring other types or negative values ​​are not unnecessarily taken care of unnecessarily.

In such a way they not at all are like multi-sets; They clearly support values ​​beyond just positive integer, and any keys set on 0 are still considered as datapoint.

You can explicitly remove or remove any counter at 0 by declining an empty counter object:

  gt; & Gt; Counter import from & gt; & Gt; & Gt; Counter ({'a': 0}) - Counter () Counter () & gt; & Gt; & Gt; Counter ({'a': 0, 'b': 1, 'c': -1}) - counter ({'b': 1})  
/ Html>

Comments