Skip to content

Commit 5e23c0a

Browse files
committed
By Zhao Kun Peng
1 parent 151987e commit 5e23c0a

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

checkio/count.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from collections import Counter
2+
def checkio(text: str) -> str:
3+
a = list(filter(nonum, text))
4+
b = []
5+
for i in a:
6+
b.append(i.lower())
7+
x = sorted(Counter(b).most_common(), key=lambda x: x[1], reverse=True)
8+
9+
def p(n):
10+
if n[1] < x[0][1]:
11+
return False
12+
else:
13+
return True
14+
15+
return sorted(list(filter(p, x)), key=lambda x: x[0])[0][0]
16+
17+
18+
def nonum(n):
19+
if n.isdigit():
20+
return False
21+
if ord(n) < 65 or 90 < ord(n) < 97 or ord(n) > 122:
22+
return False
23+
else:
24+
return True
25+
26+
27+
if __name__ == '__main__':
28+
print("Example:")
29+
print(checkio("Hello World!"))
30+
31+
# These "asserts" using only for self-checking and not necessary for auto-testing
32+
assert checkio("Hello World!") == "l", "Hello test"
33+
assert checkio("How do you do?") == "o", "O is most wanted"
34+
assert checkio("One") == "e", "All letter only once."
35+
assert checkio("Oops!") == "o", "Don't forget about lower case."
36+
assert checkio("AAaooo!!!!") == "a", "Only letters."
37+
assert checkio("abe") == "a", "The First."
38+
print("Start the long test")
39+
assert checkio("a" * 9000 + "b" * 1000) == "a", "Long."
40+
print("The local tests are done.")

0 commit comments

Comments
 (0)