Write a function that efficiently finds all anagrams of a given word from a large list of words. The solution must be optimized for performance, handling datasets with 100,000+ words in under 1 second.
find_anagrams("race", ["care", "acer", "Race", "carr", "arc"])
➞ ["care", "acer", "Race"]
def find_anagrams(word, word_list):
pass
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
def test_find_anagrams():
assert find_anagrams("listen", ["enlists", "google", "inlets", "banana", "silent", "Listen"]) == ["inlets", "silent", "Listen"]
assert find_anagrams("race", ["care", "acer", "Race", "carr", "arc"]) == ["care", "acer", "Race"]
assert find_anagrams("evil", ["vile", "Live", "vein", "vial"]) == ["vile", "Live"]
assert find_anagrams("python", ["typhon", "YPTHON", "java", "script"]) == ["typhon", "YPTHON"]
print("All test cases pass!")
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)