Generate a Python script to filter a list of words by length.
words = ['cat', 'dog', 'elephant', 'bear', 'dragon']
def filter_by_length(words, length):
    return [word for word in words if len(word) == length]