I am experimenting with Python standard library Collections.
I have a Counter of things as
>>> c = Counter('achdnsdsdsdsdklaffaefhaew')
>>> c
Counter({'a': 4,
'c': 1,
'h': 2,
'd': 5,
'n': 1,
's': 4,
'k': 1,
'l': 1,
'f': 3,
'e': 2,
'w': 1})
What I want now is to somehow get subset of this counter as another Counter object. Just like this:
>>> new_c = do_subset(c, [d,s,l,e,w])
>>> new_c
Counter({'d': 5,
's': 4,
'l': 1,
'e': 2,
'w': 1})
Thank you in advance.
You could simply build a dictionary and pass it to Counter:
Output