Find the letters with the highest frequency

Source: Internet
Author: User

Rules
    1. 给你一个其中包含不同的英文字母和标点符号的文本,你要找到其中出现最多的字母,返回的字母必须是小写形式,当检查最想要的字母时,不区分大小写,所以在你的搜索中 "A"=="a"。 请确保你不计算标点符号,数字和空格,只计算字母;
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.