Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108206
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Pylint prefers list comprehension over filter... |
| Date | Fri, 6 May 2016 11:33:39 +1000 |
| Lines | 34 |
| Message-ID | <mailman.421.1462498422.32212.python-list@python.org> (permalink) |
| References | <572BF2BF.6000000@icloud.com> <CAPTjJmp96gew0igPzVj-pa1aV1CzcAUeTtdqnhJTKV1sqUyT-g@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de 0VhO5BBhtF9ZQMGfibLi+g6rjQjWLPxir4aRZxpKlzdg== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:skip:c 10': 0.07; 'cc:addr:python-list': 0.09; 'iterate': 0.09; 'argument': 0.15; 'instead.': 0.15; "skip:' 30": 0.15; '2016': 0.16; 'disabled.': 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; 'thread.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'function,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'subject:list': 0.26; 'earlier': 0.27; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'function': 0.28; 'fine': 0.28; 'exists,': 0.29; 'code': 0.30; 'call,': 0.33; 'rule': 0.33; 'case,': 0.34; "skip:' 20": 0.34; 'except': 0.34; 'that,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'filter': 0.35; 'replaced': 0.35; 'according': 0.36; 'but': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'wrong': 0.38; 'does': 0.39; 'skip:x 10': 0.40; 'reach': 0.61; 'it!': 0.64; 'chrisa': 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=QUjiwQ47SjaOEBpJAz3QWtUYdWvaij7Ld2uJREVmuys=; b=pyG4brWYEou+1XnT1M9v5Tkxn1U1HSDJ8LZT2Smqf7eKEfKpQtKHO6WuhFQGppyWXB Rhf9lBTpBky5D7WiZhbkRv2b+zFNjjSTINugOAEZ31FXPNmkboPzPmp7ofkCFrZ8YlG9 Gb7fDCK9Emf4/qM1NEyVKsIMfjRs0HMYXLnBTlzYRcLUgjA6mj5k3cBnUWHViUJhFwj2 K2kfgLqltY3iINzi6e+yMVORU2XS7M4dvjgq7nX3/I2XICTgh1yt0gVfyK2SZCHFbzam ocZiMXv5nsXeuwpGg0n5Xwq4HIGEPllWHja2Hcd4uzZP2u/EzaR0CTyobCvGSICD/VJe vdhg== |
| 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=QUjiwQ47SjaOEBpJAz3QWtUYdWvaij7Ld2uJREVmuys=; b=mbxfBtBlLO9Qs4ySKLu2g9l1V+o0tYPMRMdNuetFjrXIxitaf7LBWyvNjpidl2WKNo 32p33PQ82JJc7DoXOQVquNCAWEelYdAPYbySgUPlL8T0xdHI457Ioh9BGrypJZiMDVP3 zQKHiC7WPKX9R0WiMwCz7N+E8wvo7ZMaRErOfjKOdp635FQs3OpnGxQVxH95bRE1N/6v asmZoUMHjuB1rw7lfZ5P3sHGXZowLNhRFduQGs1vPWQ1vTg/0LlnTOMWhS5snKtNhtd5 JnceEvqMJXbpOx1ZzhYDIcElyggalwzr592x318fTxbNJY9xk4Qpey+SV8JdwKo9F/tp YdTw== |
| X-Gm-Message-State | AOPr4FXIH3fS3fR/cjfa+vUMihXuZCqLxxBMPUNKLHRI/fgsNcRk//2TkHIIUjn4KWQNG4/DkMPKp/l0LnTTVw== |
| X-Received | by 10.25.25.9 with SMTP id 9mr143551lfz.37.1462498419816; Thu, 05 May 2016 18:33:39 -0700 (PDT) |
| In-Reply-To | <572BF2BF.6000000@icloud.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAPTjJmp96gew0igPzVj-pa1aV1CzcAUeTtdqnhJTKV1sqUyT-g@mail.gmail.com> |
| X-Mailman-Original-References | <572BF2BF.6000000@icloud.com> |
| Xref | csiph.com comp.lang.python:108206 |
Show key headers only | View raw
On Fri, May 6, 2016 at 11:26 AM, Christopher Reimer <christopher_reimer@icloud.com> wrote: > 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? Nothing wrong with filter. Since join() is going to iterate over its argument anyway, you don't need the list() call, you can remove that, but you don't have to go for comprehensions: ''.join(filter(str.isupper, string)) Rule of thumb: If the function already exists, use filter or map. If you would be using filter/map with a lambda function, reach for a comprehension instead. In this case, str.isupper exists, so use it! ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Pylint prefers list comprehension over filter... Chris Angelico <rosuav@gmail.com> - 2016-05-06 11:33 +1000
csiph-web