Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Pylint prefers list comprehension over filter... Date: Fri, 6 May 2016 13:18:44 +1000 Lines: 25 Message-ID: References: <572BF2BF.6000000@icloud.com> <1462498631.232041.599637409.25D91C08@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de wtC/ljulzGcnJJ0frFR3ZwwXT2zcn3NBBue22rtb7qrg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.031 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; '[1,': 0.09; 'python': 0.10; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'obviously': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'subject:list': 0.26; 'linux': 0.26; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'dan': 0.29; 'everyone': 0.31; 'maybe': 0.33; 'shorter': 0.33; 'definition': 0.34; 'received:google.com': 0.35; 'filter': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'wanted': 0.37; 'received:209': 0.38; 'means': 0.39; 'rather': 0.39; 'more': 0.63; 'better.': 0.66; 'results.': 0.67; 'hey,': 0.75; '5.3.1': 0.84; 'chrisa': 0.84; 'received:209.85.215.42': 0.84; 'subject:over': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=7K6Uswv/C2AQyor52sFbMzIdIpqLuToRsw2AnGvAMzo=; b=wROdKLCtqI/DLMJWhLMuWzxgrQ5rrmOeM17t2LmLd5H8SKwUUrKB/XcpowOo0p4gzp onauUpD55bCRLXvQwlEKeq8+Yx3s/3j/vK305KJtoA2c6EBRxKbhCzydq5R961fdyPGd KQpdXLAHK34/BaWUDW+OTE9KHUCbcemEkdyj3mkX3ngLvjAdFOvYEz7+iWzjO5/aOXZo DzQ+Bc33lGS0Ww2q/QS693ljHlaC9H2c5e30vNfa3b/dizgLBCRa419cDpFWLPckN+wV Morfgu5nrNqgCuGHGK3vWCWzb7aNt3PiK7Mfvrkf4+sUiIAADWk7nMvqnCpPrhLQGQrp h2FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=7K6Uswv/C2AQyor52sFbMzIdIpqLuToRsw2AnGvAMzo=; b=EtDssNEeO1UlBIB9h6rkHNHicBJlQXF2wvo42B9MWvbtQC8pi+gnKbT4YTrjmbtY37 odXIjUPuOnHoGFkITAlTAI79Cdp1aPXIfpnahMkF4sm9hFBwebYwwKPTksyGJWiS6/aW H8WNGAKg2mGzqrYN5jpG1PV03QOB9y5SMrRYADnk20hVF2q6Ru+WrmaQpkHt8NSdryiM nD0DxmrETD9GIzJ0FmqPTTPfUFCrsoMIZy+YLjo+AlmxGW+OFR3fCl1txANVWxn+p1kR 84G6OJtX7RqlzSttGFqns5FIg4YoA96b+KeAtZntGAjAWFllt/rpDub1LzOrHz+lSEDV 5DBA== X-Gm-Message-State: AOPr4FX1iyvkzVw4LMxaudyfnus3PTt6Jhi1clTF/Oo4JJzCp9UoxuzUYluKjiCWlkPaeyRYIWJR/Y3lt5PfZg== X-Received: by 10.25.158.149 with SMTP id h143mr8656022lfe.135.1462504724609; Thu, 05 May 2016 20:18:44 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <572BF2BF.6000000@icloud.com> <1462498631.232041.599637409.25D91C08@webmail.messagingengine.com> Xref: csiph.com comp.lang.python:108215 On Fri, May 6, 2016 at 1:07 PM, Dan Sommers wrote: > On Fri, 06 May 2016 02:46:22 +0000, Dan Sommers wrote: > >> Python 2.7.11+ (default, Apr 17 2016, 14:00:29) >> [GCC 5.3.1 20160409] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> filter(lambda x:x+1, [1, 2, 3, 4]) >> [1, 2, 3, 4] >> >> Python 3.5.1+ (default, Apr 17 2016, 16:14:06) >> [GCC 5.3.1 20160409] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> filter(lambda x:x+1, [1, 2, 3, 4]) >> > > Muphrey's Law strikes again. That lambda function is obviously a > leftover from a call to *map* rather than a call to *filter*, but thanks > everyone for not laughing and pointing. Hey, maybe you wanted to filter out all the -1 results. Maybe you have a search function that returns zero-based offsets, or -1 for "not found". Seems reasonable! And "x+1" is way shorter than "x!=-1", which means by definition that it's better. ChrisA