Find the letters with the highest frequency

Source: Internet
Author: User

Title: give you a text containing different English letters and punctuation, you want to find the most important letters, the letters returned must be lowercase, when checking the most wanted letters, is not case-sensitive, so in your search   "a"  ==  "a".   Make sure you don't count punctuation, numbers and spaces, only the letters. If you find   two or more than two letters with the same frequency,  return the letters that appear 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? oneoops! AAAOOO!!!! Abe correct result: LOEOAA problem-solving ideas: First Delete non-alphabetic characters and all the letters into lowercase, and then count the word frequency of each letter, and then find the corresponding letter according to the maximum word frequency, the result may be more than, it is OK, the order is good, and finally the first value of the list after sorting out. Script: Import redef checkio (text):     text = re.sub (R ' [^a-zA-Z] ',  ',  text.lower ())     mydict = {}    for letter  In set (text):         mydict[letter] = text.count (letter )     mylist = []    for each_item in  Mydict.keys ():         if mydict[each_item] == max ( Mydict.values ()):            mylist.append (Each_item)     mylist.sort ()      RETURN MYLIST[0]


This article is from the "Last Night Stars" blog, please make sure to keep this source http://yestreenstars.blog.51cto.com/1836303/1661643

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.