Skip to content

Instantly share code, notes, and snippets.

@hkamran80
Created January 1, 2019 18:49
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 hkamran80/05d35a0a9764145b1ba0958bdc9f627b to your computer and use it in GitHub Desktop.
Save hkamran80/05d35a0a9764145b1ba0958bdc9f627b to your computer and use it in GitHub Desktop.
Anagram Finder
"""
Anagram
Contributors:
:: H. Kamran [@hkamran80] (author)
Version: 0.0.1
Last Updated: 2019-01-01, @hkamran80
"""
import requests
word_list_url = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt"
word_list = requests.get(word_list_url).text.split("\n")
def anagram(letters: list, word_len: int):
words = []
for word in word_list:
if len(word) == word_len:
checks = 0
for l in letters:
wrd = list(word)
try:
if l in wrd:
checks += 1
except ValueError:
pass
if checks == len(word) == word_len:
words.append([word, len(word)])
return words
if __name__ == "__main__":
while True:
query = input("Query > ")
if "exit" in query:
break
else:
results = anagram(list(input("Letters: ")), int(input("Word Length: ")))
print("Total Results: {}".format(len(results)))
for r in results:
print(r[0], "(" + str(r[1]) + ")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment