Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Most Wanted Letter by DahliaSR
from re import findall
from collections import Counter
def checkio(text):
# lets get rid of any non letter chars and upper case chars
cleaned_text = findall(r'[^\d\W]', text.lower())
# now we count
cnt = Counter(cleaned_text).most_common()
# find the most frequent and "smallest" letter
max_val = max(v for k, v in cnt)
return min(char for char, count in cnt if count == max_val)
if __name__ == '__main__':
assert(checkio("Hello World!") == "l")
assert(checkio("How do you do?") == "o")
assert(checkio("One") == "e")
assert(checkio("Oops!") == "o")
assert(checkio("AAaooo!!!!") == "a")
assert(checkio("abe") == "a")
May 25, 2016
Comments: