Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108215
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Pylint prefers list comprehension over filter... |
| Date | 2016-05-06 13:18 +1000 |
| Message-ID | <mailman.427.1462504727.32212.python-list@python.org> (permalink) |
| References | (1 earlier) <1462498631.232041.599637409.25D91C08@webmail.messagingengine.com> <mailman.422.1462498634.32212.python-list@python.org> <ngh0hu$4og$1@dont-email.me> <ngh1pb$4og$2@dont-email.me> <CAPTjJmpiBP3hDSZrzX8YQZFC-0G3OM_ZVg3yfpG+MNv9B7S_OA@mail.gmail.com> |
On Fri, May 6, 2016 at 1:07 PM, Dan Sommers <dan@tombstonezero.net> 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]) >> <filter object at 0x7f26a9ef3320> > > 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Pylint prefers list comprehension over filter... Stephen Hansen <me@ixokai.io> - 2016-05-05 18:37 -0700
Re: Pylint prefers list comprehension over filter... Dan Sommers <dan@tombstonezero.net> - 2016-05-06 02:46 +0000
Re: Pylint prefers list comprehension over filter... Chris Angelico <rosuav@gmail.com> - 2016-05-06 12:55 +1000
Re: Pylint prefers list comprehension over filter... Stephen Hansen <me+python@ixokai.io> - 2016-05-05 19:57 -0700
Re: Pylint prefers list comprehension over filter... Steven D'Aprano <steve@pearwood.info> - 2016-05-06 22:42 +1000
Re: Pylint prefers list comprehension over filter... Dan Sommers <dan@tombstonezero.net> - 2016-05-06 03:07 +0000
Re: Pylint prefers list comprehension over filter... Chris Angelico <rosuav@gmail.com> - 2016-05-06 13:18 +1000
Re: Pylint prefers list comprehension over filter... Christopher Reimer <christopher_reimer@icloud.com> - 2016-05-07 12:37 -0700
csiph-web