You are given a text, which contains different english letters and punctuation symbols. You should find the most frequent letter in the text. The letter returned must be in lower case.
While checking for the most wanted letter, casing does not matter, so for the purpose of your search, "A" == "a". Make sure you do not count punctuation symbols, digits and whitespaces, only letters.
If you have two or more letters with the same frequency, then return the letter which comes first in the latin alphabet. For example -- "one" contains "o", "n", "e" only once for each, thus we choose "e".
Input: A text for analysis as a string.
Output: The most frequent letter in lower case as a string.
Example:
checkio("Hello World!") == "l"
checkio("How do you do?") == "o"
checkio("One") == "e"
checkio("Oops!") == "o"
checkio("AAaooo!!!!") == "a"
checkio("abe") == "a"
* 가장 많은 문자를 출력한다.
* 소문자로 출력해야한다.
* 가장 많은 문자가 두개 이상이면, 알파벳 순서 중 가장 빠른 것으로 출력한다.
-풀이
def checkio(text: str) -> str:
total = 0
lower = text.lower()
for i in lower:
if i.isalpha():
if lower.count(i) > total:
most = i
total = lower.count(i)
elif lower.count(i) == total:
if i < most: #sorting
most = i
total = lower.count(i)
return most
'취미생활 > CheckIO' 카테고리의 다른 글
[checkIO]Home 06.Sort Array by Element Frequency (0) | 2020.02.13 |
---|---|
[checkIO]Home 05.Non-unique Elements (0) | 2020.02.11 |
[checkIO]Home 04.Time Converter (24h to 12h) (0) | 2020.02.11 |
[checkIO]Home 02. House Password (0) | 2020.02.09 |
[checkIO]Home 01.All the Same (1) | 2020.02.09 |