Skip to content

Instantly share code, notes, and snippets.

/Error.py Secret

Created September 14, 2015 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/54c5ac2b125466a633a5 to your computer and use it in GitHub Desktop.
Save anonymous/54c5ac2b125466a633a5 to your computer and use it in GitHub Desktop.
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