How do I make a function that returns a list of anagrams of words passed as a parameter, found in a pre-defined lexicon?

Viewed 94

I am given a pre-defined lexicon saved in an external file, which is a list of words sorted from a to z. I am then asked to make a function, which takes a word as a parameter and returns a list of all the anagrams of that word found in the lexicon stated above. Edit: I cannot use the set() or sorted() functions or import modules. My code :

from lexicon import LEXICON
def anagrams(word):
    list=[]
    for i in range(len(LEXICON)):
        if i == word:
            if i in [i+1 : len(LEXICON)]:
                list.append(i)
    return list
0 Answers
Related