check if key in dictionary python count 2b1 add if it is

Solutions on MaxInterview for check if key in dictionary python count 2b1 add if it is by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "check if key in dictionary python count 2b1 add if it is"
Lennard
02 May 2018
1from collections import defaultdict
2dct = defaultdict(int)
3
4for key in data:
5  dct[key] += 1
6
7# defaultdict(<type 'int'>, {'a': 4, 'c': 3, 'b': 2, 'd': 1})