I am relatively new to lambda functions and this helped me figure it out. I have a set of words that have an average length of 3.4 and a list of words = ['hello', 'my', 'name', 'is', 'lisa']
I want to compare the word length with the average length and print only words that exceed the average length
average = 3.4
words = ['hello', 'my', 'name', 'is', 'lisa']
print(filter(lambda x: len(words) > avg, words))
so in this case I want
['hello', 'name', 'lisa']
but instead I get:
<filter object at 0x102d2b6d8>
source
share