Skip to content

Instantly share code, notes, and snippets.

@mburke05
Created November 6, 2015 20:51
Show Gist options
  • Save mburke05/22e13c452b49c4814b5e to your computer and use it in GitHub Desktop.
Save mburke05/22e13c452b49c4814b5e to your computer and use it in GitHub Desktop.
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