Created
April 28, 2016 12:14
-
-
Save PlugaruT/a20bff20fec63f199220be3e2a35bb04 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
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