-
-
Save anonymous/54c5ac2b125466a633a5 to your computer and use it in GitHub Desktop.
CheckIO. The most wanted letter bug.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkio(text): | |
def checkEqual(lst): | |
return lst[1:] == lst[:-1] | |
counted = {} | |
text = text.lower() | |
for i in text: | |
if i not in counted: | |
if i.isalpha(): | |
counted[i] = text.count(i) | |
else: | |
counted[i] = -1 | |
if checkEqual(counted.values()): | |
return min(counted) | |
else: | |
return max(counted, key=counted.get) | |
if __name__ == '__main__': | |
assert checkio(u"fdbbss") == "b", "fdbbss!=b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkio(text): | |
counted = {} | |
text = text.lower() | |
for i in text: | |
counted[i] = counted.get(i, 0 if i.isalpha() else -1000000) + 1 | |
val = max(counted.values()) | |
freq = [k for (k, v) in counted.items() if v == val] | |
return min(freq) | |
if __name__ == '__main__': | |
assert checkio(u"fdbbss") == "b", "fdbbss!=b" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment