Skip to content

Instantly share code, notes, and snippets.

/Error.py Secret

Created Sep 14, 2015
Embed
What would you like to do?
CheckIO. The most wanted letter bug.
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"
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