Rules
给你一个其中包含不同的英文字母和标点符号的文本,你要找到其中出现最多的字母,返回的字母必须是小写形式,当检查最想要的字母时,不区分大小写,所以在你的搜索中 "A"=="a"。 请确保你不计算标点符号,数字和空格,只计算字母;
- If you find two or more two or more letters with the same frequency, return the letter that appears first in the alphabet. For example "One" contains "O", "n", "E" each letter at a time, so we select "E".
Test data
Hello World!
How do you do?
One
Oops!
AAaooo!!!!
abeTarget results
l
o
e
o
a
aThinking of solving problems
First delete non-letter characters and all the letters into lowercase, and then count the word frequency of each letter, and then according to the maximum word frequency to find the corresponding letter, the result may be more than, OK, the order is good, and finally the first value of the sorted list output can be.
Script
ImportRedefCheckio (text): Text= Re.sub (r'[^a-za-z]',"', Text.lower ()) Mydict= {} forLetterinchSet (text): Mydict[letter]=Text.count (letter) MyList= [] forEach_iteminchMydict.keys ():ifMydict[each_item] = =Max (Mydict.values ()): Mylist.append (Each_item) mylist.sort ()returnMylist[0]text=" "Hello world! How does it do? oneoops! AAAOOO!!!! Abe" " forLineinchText.split ('\ n'): PrintCheckio (line)
Find the letters with the highest frequency