【发布时间】:2018-01-15 08:07:29
【问题描述】:
此问题与:Python Counter Comparison as Bag-type
在 Python 3 中,比较两个计数器将导致“TypeError: unorderable types:Counter() > Counter()”。
对于 Python 中的集合,我们可以这样做: set1
【问题讨论】:
-
子集/超集比较很容易用 Counters 来完成。例如,要检查
c1是否是c2的子集,您可以执行not c1-c2或all(c2[x] >= c1[x] for x in c1)之类的操作。
标签: python comparator multiset