Why doesn't Pylint like built-in functions?

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?


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.

A line like this in your pylintrc file will quiet the warning:

disable=W0141

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

List comprehension is recommended in the tutorial example, which states

it’s more concise and readable.

and by most answerers on SO's Python List Comprehension Vs. Map where it is

  1. more efficient to use list comprehension than filter if you are defining a lambda each time
  2. maybe more readable (and with similar efficiency) to use filter if the function is pre-defined
  3. necessary to use filter and map if you
    • map map,
    • curry map, or
    • use functional programming

TL;DR: use list comprehension in most cases


I ran into the same problem and could not figure out

why the built-in function `input' is bad. I you intend

to disable it:

pylint --bad-functions="[map,filter,apply]" YOUR_FILE_TO_CHECK_HERE

Once you like the settings:

pylint --bad-functions="[map,filter,apply]" --some-other-supercool-settings-of-yours
--generate-rcfile > test.rc

Verify that your settings are in the file, e.g.:

cat test.rc | grep -i YOUR_SETTING_HERE

After that you can use this file locally

pylint --rcfile test.rc --your-other-command-line-args ...

or even use it as your default rcfile. For this I kindly refer you to

pylint --long-help