Given the string:
a=\'dqdwqfwqfggqwq\'
How do I get the number of occurrences of each character?
You can do this:
listOfCharac={} for s in a: if s in listOfCharac.keys(): listOfCharac[s]+=1 else: listOfCharac[s]=1 print (listOfCharac)
Output {'d': 2, 'f': 2, 'g': 2, 'q': 5, 'w': 3}
{'d': 2, 'f': 2, 'g': 2, 'q': 5, 'w': 3}
This method is efficient as well and is tested for python3.