How to convert a counter from a list of element and count pairs to a dictionary in Python

1 Answer

0 votes
from collections import Counter

counter = Counter()
for ch in "python pro":
    counter[ch] += 1

print(dict(counter.items()))



'''
run:

{'p': 2, 'y': 1, 't': 1, 'h': 1, 'o': 2, 'n': 1, ' ': 1, 'r': 1}
 
'''

 



answered Jul 26, 2019 by avibootz

Related questions

2 answers 219 views
1 answer 139 views
1 answer 154 views
2 answers 177 views
...