[Tutor] another better way to do this ?

eryksun eryksun at gmail.com
Sun Jan 12 18:54:32 CET 2014


On Sun, Jan 12, 2014 at 8:21 AM, Peter Otten <__peter__ at web.de> wrote:
>
> OP: You'll get bonus points (from me, so they're pointless points, but
> still) if you can solve this (including the fifth apocryphal test case)
> using the collections.Counter class.

Hint:

    >>> print(Counter.__sub__.__doc__)
     Subtract count, but keep only results with positive counts.

            >>> Counter('abbbc') - Counter('bccd')
            Counter({'b': 2, 'a': 1})

    >>> product = Counter('t-shirt')
    >>> product - Counter('wsx0-=mttrhix')
    Counter()
    >>> product - Counter('wsx0-=mtrhix')
    Counter({'t': 1})

`Counter` has multiset methods for the operators +, -, &
(intersection; min count), and | (union; max count). However, it
doesn't implement the `issubset` or `issuperset` methods of `set`, nor
the ordered comparisons (<, >, <=, >=) that depend on them.


More information about the Tutor mailing list