DEV Community

Cover image for Identifying the alphabet character that appears most frequently in a statement.
Tadiwa Carlton Chiwele
Tadiwa Carlton Chiwele

Posted on

Identifying the alphabet character that appears most frequently in a statement.

Hello.
I ran into an issue when trying to solve an exercise as a newbie in Python.
The task is to identify the alphabet character that appears most frequently in a statement.
I wrote the following:

sentence = “This is a common interview question”

for char in sentence:
countingchar = sentence.count(char)
chardict = {char: countingchar}
print(chardict )

As you can see, I tried to make a dictionary with every letter in the text, but instead of producing one dictionary with many key-value pairs, the effort produced several dictionaries with just one key. I can't combine these dictionaries into one dictionary, and that is my issue.
What ought I to do?
Can you assist me in solving this problem using this method?
Please let me know if I've missed any lines of code or have written any.
I want to comprehend and learn.

I value your assistance and time.

Top comments (0)