Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Created October 19, 2017 03:00
Show Gist options
  • Save clamytoe/18173f9b5139d99a336372306936c945 to your computer and use it in GitHub Desktop.
Save clamytoe/18173f9b5139d99a336372306936c945 to your computer and use it in GitHub Desktop.
secret.py
# secret message code challenge
# https://dev.to/rpalo/secret-message-7do
from string import ascii_lowercase
from long_string import code
ALPHA = ascii_lowercase + '_'
def count(letters):
counts = {}
for l in letters:
if l in ALPHA:
counts[l] = counts.get(l, 0) + 1
return counts
def decode(dictionary):
s_counts = sorted(
dictionary,
key=dictionary.get,
reverse=True
)
cut_off = s_counts.index('_')
secret = ''.join([t for i, t in enumerate(s_counts) if i < cut_off])
return secret
if __name__ == '__main__':
counted = count(code)
word = decode(counted)
print(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment