def sort_by_length(words):
    """Sort a list of words in reverse order by length.

    This is the version in the book; it is stable in the sense that
    words with the same length appear in the same order

    words: list of strings

    Returns: list of strings
    """
    t = []
    for word in words:
        t.append((len(word), word))

    t.sort(reverse=True)

    res = []
    for length, word in t:
        res.append(word)
    return res