lexicographical order in reverse order
<p>I need to make a code that sorts a list of words and puts them in lexicographical order from reverse. For example, given the list <code>["harry", "harra", harrb"]</code> I need a way to reverse each word so the list becomes <code>["yrrah", "arrah","brrah"]</code>. Then I need to sort it by lexicographical order and reverse it back to its original order. So it would look like <code>["harra", "harrb", "harry"]</code>. I'm taking words from a file <code>ifile</code> but for this code I'm only ordering words with a certain number of letters "n". </p>

<p>Here is my code so far:</p>

<pre><code>def getRhymeSortedCount(n,ifile,file):
    word_list = []
    for word in ifile:
        if len(word) == n:
            word_list.append(word.strip())
    arr = word_list
    arr.sort(key = lambda x : x[::-1])
    ofile.write("\n".join(word_list))
</code></pre>

<p>It correctly orders the words by their last letter, but isn't taking the words with number of letters = "n" how can i change my len statement to grab only the words with n letters?</p>