Created
November 6, 2015 20:51
-
-
Save mburke05/22e13c452b49c4814b5e 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 | |
test_string = ["spare", "hello", "pears", "world", "reaps"] | |
def find_anagrams(strings, word): | |
"""Takes a list of strings as an argument and returns a list of strings that are anagrams of | |
the provided word like so: | |
find_anagrams(["spare", "hello", "pears", "world", "reaps"], "parse") = ["spare", "pears", "reaps"] | |
""" | |
return [string for string in strings if sorted(string) == sorted(word)] | |
class AnagramsTestCase(unittest.TestCase): | |
def test_base(self): | |
self.assertEqual(find_anagrams(test_string,'parse'),['spare', 'pears', 'reaps']) | |
def test_hello(self): | |
self.assertEqual(find_anagrams(test_string,'hello'),['hello']) | |
def test_world(self): | |
self.assertEqual(find_anagrams(test_string,'world'),['world']) | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment