Pylint prefers list comprehension over filter...

Christopher Reimer christopher_reimer at icloud.com
Thu May 5 21:26:23 EDT 2016


Greetings,

Below is the code that I mentioned in an earlier thread.

     string = "Whiskey Tango Foxtrot"
     ''.join(list(filter(str.isupper, string)))

     'WTF'

That works fine and dandy. Except Pylint doesn't like it. According to 
this link, list comprehensions have replaced filters and the Pylint 
warning can be disabled.

http://stackoverflow.com/questions/3569134/why-doesnt-pylint-like-built-in-functions

Here's the replacement code using list comprehension:

     ''.join([x for x in string if x.isupper()])

Which is one is correct (Pythonic)? Or does it matter?

Thank you,

Chris R.



More information about the Python-list mailing list