[Tutor] failed filter result

Jim Mooney cybervigilante at gmail.com
Mon Apr 6 16:05:27 CEST 2015


Why did this fail where it did? It failed at listing the result of the
filter of a word list, but I figured if it failed, it would have done so at
the filter.

>>> words = open('5desk.txt').readlines()
>>> k = [word.rstrip for word in words]
>>> len(k)
61406
>>> p = filter(lambda word: len(word) > 10, k)
>>> p
<filter object at 0x01992F30>
>>> list(p)
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
  File "<interactive input>", line 1, in <lambda>
TypeError: object of type 'builtin_function_or_method' has no len()

-- 
Jim

I can't think of a clever tagline today, so just imagine I said something
clever.


More information about the Tutor mailing list