max(…. , key= ) function

max

https://py.checkio.org/en/mission/most-wanted-letter/

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.

 

해1: regualr expression을 이용

re.PNG

해2: count 함수 이용

count

해3: max함수 이용 (사이트에서 베스트 답변으로 뽑힌건데 어떤사람이 단 2줄로 풀어놨음.)

max_key

max함수 사용법은 윗부분 참조

이걸 단 한줄로 줄이면

max 1

함수계산을 해야되서 속도는 2줄짜리보다 약간 떨어질듯.

댓글 남기기