Word analysis

Article Directory

problem

Xiaolan is learning a magical language. The words in this language are made up of lowercase English letters. Some words are very long, far exceeding the length of normal English words.
Xiaolan had been learning for a long time and couldn't remember some words. He planned not to remember these words completely, but to distinguish words based on which letter appeared the most.
Now, please help Xiaolan. After giving a word, help him find the most frequent letter and the number of times this letter appears.

[Input format] The
input line contains one word, and the word is only composed of lowercase English letters.

[Output format]
Output two lines, the first line contains an English letter, which indicates which letter appears most frequently in the word.
If there are multiple letters that appear the same number of times, the one with the smallest lexicographic order is output.
The second line contains an integer that represents the number of times the most frequent letter appears in the word.

【Sample input】
lanqiao

[Sample output]
a
2

[Sample input]
longlonglongistoolong

【Sample output】
o
6

[Evaluation use case scale and conventions]
For all evaluation use cases, the input word length should not exceed 1000.

Idea code

Traverse the words, count the length of each letter, form a letter-length dictionary, and then output it. Pay attention to the same number of comparisons.

password = input()
dic = {
    
    }
for i in password:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

print(dic)

ma = 0
l=[]
for i in dic:
    if dic[i] >= ma:
        ma = dic[i]
        l.append(i)
print(l)
print(max(l),'\n',dic[max(l)])
        
 

Guess you like

Origin blog.csdn.net/qq_49821869/article/details/115262194