python how to subtract values from dictionaries

Solutions on MaxInterview for python how to subtract values from dictionaries by the best coders in the world

showing results for - "python how to subtract values from dictionaries"
Michele
30 Jul 2020
1>>> from collections import Counter
2>>> d1 = Counter({'a': 10, 'b': 9, 'c': 8, 'd': 7})
3>>> d2 = Counter({'a': 1, 'b': 2, 'c': 3, 'e': 2})
4>>> d3 = d1 - d2
5>>> print d3
6Counter({'a': 9, 'b': 7, 'd': 7, 'c': 5})
7