Pylint prefers list comprehension over filter...

Christopher Reimer christopher_reimer at icloud.com
Sat May 7 15:37:20 EDT 2016


On 5/5/2016 7:57 PM, Stephen Hansen wrote:
> On Thu, May 5, 2016, at 07:46 PM, Dan Sommers wrote:
>> On Thu, 05 May 2016 18:37:11 -0700, Stephen Hansen wrote:
>>
>>>      ''.join(x for x in string if x.isupper())
>>> The difference is, both filter and your list comprehension *build a
>>> list* which is not needed, and wasteful. The above skips building a
>>> list, instead returning a generator ...
>> filter used to build a list, but now it doesn't (where "used to" means
>> Python 2.7 and "now" means Python 3.5; I'm too lazy to track down the
>> exact point(s) at which it changed):
> Oh, didn't know that. Then again the OP was converting the output of
> filter *into* a list, which wasted a list either way.

My line of code was something I copied off the Internet and modified it 
until it did I exactly what I wanted it to do. That means that the many 
Python 2 code examples available on the Internet are using a redundant 
list operation with Python 3. Isn't that a "smell" that pylint should 
pick up on?

Thank you,

Chris R.



More information about the Python-list mailing list