How to return all list elements of a given length?

Solution 1:

I would use a list comprehension:

def by_size(words, size):
    return [word for word in words if len(word) == size]

Solution 2:

return filter(lambda x: len(x)==size, words)

for more info about the function, please see filter()