Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (26.4k points)

Consider the below string:

a='dqdwqfwqfggqwq'

Can anyone tell me, How to get the no. of occurrences of each character?

1 Answer

0 votes
by (26.4k points)

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}

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:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...