How to use a badly built-in filter?

This may be the main question, but I'm interested in knowing if the filter uses inline code, but pylint reports

W: 67,13: Used builtin function 'filter' (bad-builtin)

How come it is bad?

+4
source share
1 answer

You will need to decide whether you care about this warning or not.

filter(my_filter, my_iterable)

is equivalent to:

[item for item in my_iterable if my_filter(item)]

In python 3, it filteracts like a generator, which means it lazily evaluates things, for example:

(item for item in my_iterable if my_filter(item))

I would ignore this particular warning. Pyflakes can give you a more useful result.

+3
source

Source: https://habr.com/ru/post/1527151/


All Articles