Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
pretty faster then comprehension solution in Speedy category for Most Wanted Letter by danersow
from string import digits, punctuation, whitespace
from string import digits, punctuation, whitespace, ascii_lowercase
# def most_wanted(text: str) -> str:
# restr = "".join([digits, punctuation, whitespace])
# text = [j for j in text.lower() if j not in restr]
# return list(set([i for i in text if text.count(i) == text.count(max(set(text), key = text.count))]))
def most_wanted(text: str) -> str:
restr = "".join([digits, punctuation, whitespace])
for i in restr:
text = text.replace(i,"")
text = text.lower()
res = [max(set(text), key = text.count)]
for i in ascii_lowercase:
if text.count(i)==text.count(res[0]):
res.append(i)
return list(set(res))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert sorted(most_wanted("Hello World!")) == ["l"], "Hello test"
assert sorted(most_wanted("How do you do?")) == ["o"], "O is most wanted"
assert sorted(most_wanted("One")) == ["e", "n", "o"], "All letter only once."
assert sorted(most_wanted("Oops!")) == ["o"], "Don't forget about lower case."
assert sorted(most_wanted("AAaooo!!!!")) == ["a", "o"], "Only letters."
assert sorted(most_wanted("abe")) == ["a", "b", "e"], "The First."
print("Start the long test")
assert sorted(most_wanted("a" * 9000 + "b" * 1000)) == ["a"], "Long."
print("The local tests are done.")
Oct. 16, 2020
Comments: