Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108211

Re: Pylint prefers list comprehension over filter...

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Pylint prefers list comprehension over filter...
Date 2016-05-06 12:55 +1000
Message-ID <mailman.425.1462503307.32212.python-list@python.org> (permalink)
References <572BF2BF.6000000@icloud.com> <1462498631.232041.599637409.25D91C08@webmail.messagingengine.com> <mailman.422.1462498634.32212.python-list@python.org> <ngh0hu$4og$1@dont-email.me> <CAPTjJmqJmkTp85wWZm_GF1gRKSRv5UE7Ck4jZM2NBSwAnFKk-Q@mail.gmail.com>

Show all headers | View raw


On Fri, May 6, 2016 at 12:46 PM, Dan Sommers <dan@tombstonezero.net> wrote:
> 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):
>
>     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>

Most of these kinds of changes happened in 3.0, where
backward-incompatible changes were accepted. A whole bunch of things
stopped returning lists and started returning lazy iterables - range,
filter/map, dict.keys(), etc - because most of the time, they're
iterated over once and then dropped.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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