Skip to content

Instantly share code, notes, and snippets.

@alothings
Created June 24, 2016 20:16
Show Gist options
  • Save alothings/655d863a9758d6ca94744047c3ceb0b4 to your computer and use it in GitHub Desktop.
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.
'''
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