Back
Consider the below string:
a='dqdwqfwqfggqwq'
Can anyone tell me, How to get the no. of occurrences of each character?
Try the following code:
In [24]: a='dqdwqfwqfggqwq'In [25]: dict((letter,a.count(letter)) for letter in set(a))Out[25]: {'d': 2, 'f': 2, 'g': 2, 'q': 5, 'w': 3}
In [24]: a='dqdwqfwqfggqwq'
In [25]: dict((letter,a.count(letter)) for letter in set(a))
Out[25]: {'d': 2, 'f': 2, 'g': 2, 'q': 5, 'w': 3}
Are you looking for a good python tutorial? Join the python course fast and gain more knowledge in python.
To know more about this you can have a look at the following video tutorial:-
31k questions
32.8k answers
501 comments
693 users