-
-
Save anonymous/49a8967c17c8361008cf to your computer and use it in GitHub Desktop.
This file contains 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
#encoding=utf-8 | |
from collections import OrderedDict | |
def anagram_finder(word_list): | |
hash_dict = OrderedDict() | |
hash_word = lambda w: "".join(sorted(list(w))) | |
for word in word_list: | |
c = hash_word(word) | |
if c not in hash_dict: | |
hash_dict[c] = [] | |
hash_dict[c].append(word) | |
return [val for key in hash_dict if len(hash_dict[key]) > 1 for val in hash_dict[key]] | |
if __name__ == "__main__": | |
words = "cool loco pretty stanley yelnats nice joke loop" \ | |
" pool ploo egg geg mice men noodles poodles tasty testy" \ | |
"mole lame satin stain" | |
print anagram_finder(words.split()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment