Created
June 24, 2016 20:16
-
-
Save alothings/655d863a9758d6ca94744047c3ceb0b4 to your computer and use it in GitHub Desktop.
Given a list with strings and a word, find the strings that are anagrams of the word given.
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
''' | |
Return anagrams of the same word | |
To optimize in future can use bit strings | |
''' | |
def find_anagrams(list_of_anagrams, word): | |
l = [] | |
for s in list_of_anagrams: | |
if sorted(word) == sorted(s): | |
l.append(s) | |
return l | |
l = ["spare", "hello", "pears", "world", "reaps"] | |
print find_anagrams(l, "parse") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment