views:

57

answers:

1

Hi,

I have a line like this:

filter(lambda x: x == 1, [1, 1, 2])

Pylint is showing a warning:

W:  3: Used builtin function 'filter'

Why is that? is a list comprehension the recommended method?

Of course I can rewrite this like this:

[x for x in [1, 1, 2] if x == 1]

And I get no warnings, but I was wondering if there's a PEP for this?

+4  A: 

Pylint often chatters on about stuff it shouldn't. You can disable the warning in a .pylintrc file.

This page http://pylint-messages.wikidot.com/messages:w0141 indicates the problem is that filter and map have been superseded by list comprehensions.

Ned Batchelder
I didn't know about that website, thanks a lot!
igorgue
I didn't know about it either. I ran pylint with the "-i y" flag to include the message number, then I Googled "pylint W0141", and that's what I found.
Ned Batchelder