Created
September 6, 2017 09:31
-
-
Save mvallebr/16fef76bf3415aa182d866558fa7f78b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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