Union is the maximum of value in either of the input counters. >>> Counter('abbb') | Counter('bcc') Counter({'b': 3, 'c': 2, 'a': 1})
(self, other)
| 148 | return result |
| 149 | |
| 150 | def __or__(self, other): |
| 151 | '''Union is the maximum of value in either of the input counters. |
| 152 | |
| 153 | >>> Counter('abbb') | Counter('bcc') |
| 154 | Counter({'b': 3, 'c': 2, 'a': 1}) |
| 155 | |
| 156 | ''' |
| 157 | if not isinstance(other, Counter): |
| 158 | return NotImplemented |
| 159 | _max = max |
| 160 | result = Counter() |
| 161 | for elem in set(self) | set(other): |
| 162 | newcount = _max(self[elem], other[elem]) |
| 163 | if newcount > 0: |
| 164 | result[elem] = newcount |
| 165 | return result |
| 166 | |
| 167 | def __and__(self, other): |
| 168 | ''' Intersection is the minimum of corresponding counts. |