Created
July 19, 2013 22:58
-
-
Save kimslawson/6042976 to your computer and use it in GitHub Desktop.
Acrostic function for generating passphrases, contributed to https://github.com/redacted/XKCD-password-generator
This file contains hidden or 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 find_acrostic(acrostic, wordlist): | |
""" | |
Constrain choice of words to those beginning with the letters of the given word (acrostic) | |
""" | |
""" | |
# slower but more elegant. "pythonic" | |
while 1: | |
words = " ".join(rng().sample(wordlist, n_words)) | |
if acrostic.lower() == "".join(item[0] for item in words.split()).lower(): | |
return words | |
break | |
""" | |
# faster but less elegant. practical. | |
words = "" | |
for letter in acrostic: | |
while 1: | |
word = rng().choice(wordlist) | |
if word[0] == letter: | |
words += word + " " | |
break | |
return words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment