[1] Problem: https://py.checkio.org/en/mission/most-wanted-letter/
[2] My solutions
python
접기def checkio(text: str) -> str: #replace this for solution text = text.lower() word_list = list(dict.fromkeys(text)) word_dict = {} for word in word_list: if word.isalpha(): word_dict[word] = text.count(word) return sorted(word_dict.items(), key=(lambda x: (-x[1], x[0])))[0][0] if __name__ == '__main__': print("Example:") print(checkio("Hello World!")) #These "asserts" using only for self-checking and not necessary for auto-testing assert checkio("Hello World!") == "l", "Hello test" assert checkio("How do you do?") == "o", "O is most wanted" assert checkio("One") == "e", "All letter only once." assert checkio("Oops!") == "o", "Don't forget about lower case." assert checkio("AAaooo!!!!") == "a", "Only letters." assert checkio("abe") == "a", "The First." print("Start the long test") assert checkio("a" * 9000 + "b" * 1000) == "a", "Long." print("The local tests are done.")
[3] Best solution
python
접기from string import ascii_lowercase as letters checkio = lambda text: max(letters, key=text.lower().count)
'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글
[Check-IO] Conversion into CamelCase (0) | 2021.12.25 |
---|---|
[Check-IO] Conversion from CamelCase (0) | 2021.12.20 |
[Check-IO] Follow Instructions (0) | 2021.12.18 |
[Check-IO] Common Words (0) | 2021.12.16 |
[Check-IO] Sum by Type (0) | 2021.12.12 |
댓글