Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created September 6, 2017 09:31
Show Gist options
  • Select an option

  • Save mvallebr/16fef76bf3415aa182d866558fa7f78b to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/16fef76bf3415aa182d866558fa7f78b to your computer and use it in GitHub Desktop.
# Given a words.txt file containing a newline-delimited list of dictionary
# words, please implement the Anagrams class so that the get_anagrams() method
# returns all anagrams from words.txt for a given word.
#
# Bonus requirements:
# - Optimise the code for fast retrieval
# - Write more tests
# - Thread safe implementation
import unittest
class Anagrams:
def __init__(self):
self.words = open('words.txt').readlines()
def get_anagrams(self, word):
pass
class TestAnagrams(unittest.TestCase):
def test_anagrams(self):
anagrams = Anagrams()
self.assertEquals(anagrams.get_anagrams('plates'), ['palest', 'pastel', 'petals', 'plates', 'staple'])
self.assertEquals(anagrams.get_anagrams('eat'), ['ate', 'eat', 'tea'])
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment