Jabba Laci wrote:
Hi,

Pylint gives me a warning for the function "filter". As I know, this
function is not deprecated. Is the usage of list comprehensions
encouraged? Should I avoid "filter" (and why)?

This is not a pylint question but a general python question, so you seem to be 
at the wrong place :)

Nevertheless, I'll try to give an answer :)

I think indeed that list comprehensions are encouraged, and in my opinion, for 
good reasons.

Try to implement the following list comprehensions with filter (and map).

[ x for x in L if x > 3 ]

[ x + 1 for x in L if x > 3 ]

[ (x,y) for x in L if x > 3 for y in L if y < x ]

While I am sure you can write a filter/map/lambda expression that computes them, I am also sure none of your results is more readable[1] than the above list comprehensions.

For bigger list comprehensions, it gets worse.


I hope this clarifies a bit why filter is not recommended.


Albert


[1] Readable for the general Python user which typically has not seen any functional programming concepts like map and filter.
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to