Update Counter collection in python with string, not letter

You can update it with a dictionary, since add another string is same as update the key with count +1:

from collections import Counter
c = Counter(['black','blue'])

c.update({"red": 1})  

c
# Counter({'black': 1, 'blue': 1, 'red': 1})

If the key already exists, the count will increase by one:

c.update({"red": 1})

c
# Counter({'black': 1, 'blue': 1, 'red': 2})

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)