Skip to content

Instantly share code, notes, and snippets.

@PlugaruT
Created April 28, 2016 12:14
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 PlugaruT/a20bff20fec63f199220be3e2a35bb04 to your computer and use it in GitHub Desktop.
Save PlugaruT/a20bff20fec63f199220be3e2a35bb04 to your computer and use it in GitHub Desktop.
import unittest
default = ["spare", "hello", "pears", "world", "reaps"]
letters = ["abcde", "qwerty", "yuiop", "edcba"]
word_list = ["abba", "aabb", "bbaa", "abbc", "aacc"]
def find_anagrams(list_of_strings, word):
anagrams = []
for w in list_of_strings:
list_w = list(w)
list_w.sort()
list_word = list(word)
list_word.sort()
if list_w == list_word:
anagrams.append(w)
return anagrams
class AnagramsTestCase(unittest.TestCase):
def test_default_array(self):
self.assertEqual(find_anagrams(default, "parse"), ['spare', 'pears', 'reaps'])
def test_letters_array(self):
self.assertEqual(find_anagrams(letters, "cbaed"), ['abcde', 'edcba'])
def test_word_array(self):
self.assertEqual(find_anagrams(word_list, "abab"), ['abba', 'aabb', 'bbaa'])
if __name__ == '__main__':
unittest.main()
print find_anagrams(default, 'parse')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment