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


Groups > comp.lang.python > #88164

Re: Supply condition in function call

References (4 earlier) <b806441f-ea43-48a7-97a2-223cbfd6b8ff@googlegroups.com> <mailman.230.1427421404.10327.python-list@python.org> <c3df4d41-6a40-4fc1-abb2-24fbb74e499e@googlegroups.com> <5514ddee$0$12979$c3e8da3$5496439d@news.astraweb.com> <1a8eccd0-50d7-4eb3-84ec-5c7bbdb34b89@googlegroups.com>
Date 2015-03-28 01:17 +1100
Subject Re: Supply condition in function call
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.262.1427465834.10327.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Mar 28, 2015 at 12:48 AM, Rustom Mody <rustompmody@gmail.com> wrote:
> Knows some C, not much else.
> Starts studying python.
> Good until a point.
> Then suddenly hit... map, filter, and the worst of all lambda.
> More he reads less he understands.
> Tries help... Gets the above.
>
> So which do you think helps him more python 2 or 3?

Python 3, because scaring someone off filter() might push him towards
comprehensions instead :)

No, seriously: I wouldn't expect anyone to be using help(filter) in
that way. Someone who knows C and not much Python is simply not going
to stumble upon filter, but will have a task/problem in mind. From
there, either the online documentation or a Q&A forum like this or
Stack Overflow will be the next port of call, not the help for one
particular function.

And frankly, if someone says "what you want is filter()" and doesn't
explain what it does, why it's useful, and why it's better than a list
comp/genexp, is doing a poor job of helping. The most common case of
filter can be trivially converted into a genexp:

filter(lambda x: some_expression, some_iterable)
(x for x in some_iterable if some_expression)

Unlike map(), filter() doesn't accept multiple iterables, so you don't
even need to worry about zip(). The only time you really need filter()
is when you're using a pre-existing function, and even then, a genexp
is often not much worse:

filter(int, list_of_strings)
(s for s in list_of_strings if int(s))

Instead of building up more and more complex nestings of map, filter,
etc, just go straight to a genexp (or a list comp, if you're about to
wrap it in list()) and add the complexity you need. Teaching a new
Python programmer about comprehensions is MUCH more useful than
teaching him/her about map and filter.

So, no. I don't think the help() difference between Py2 and Py3 is
going to be much of a problem to a new programmer who knows only C.
Maybe one who knows only LISP, but not one who knows C.

ChrisA

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


Thread

Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-25 18:29 +0100
  Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 13:41 -0400
    Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-25 18:51 +0100
      Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 14:17 -0400
      Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 12:22 -0600
      Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 14:42 -0400
  Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 11:44 -0600
    Re: Supply condition in function call Grant Edwards <invalid@invalid.invalid> - 2015-03-25 19:53 +0000
      Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 14:49 -0600
        Re: Supply condition in function call Grant Edwards <invalid@invalid.invalid> - 2015-03-26 15:41 +0000
  Re: Supply condition in function call Terry Reedy <tjreedy@udel.edu> - 2015-03-25 14:50 -0400
  Re: Supply condition in function call Gary Herron <gherron@digipen.edu> - 2015-03-25 12:13 -0700
    Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-25 21:02 -0700
      Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-26 17:00 +1100
        Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 18:41 -0700
          Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-27 12:56 +1100
            Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 19:21 -0700
              Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-27 15:34 +1100
                Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-27 06:48 -0700
                Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-28 01:17 +1100
                Re: Supply condition in function call Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-27 16:00 +0000
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 18:32 +1100
                Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-28 18:45 +1100
            Re: Supply condition in function call Larry Hudson <orgnut@yahoo.com> - 2015-03-27 17:26 -0700
              Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-27 18:27 -0700
              Re: Supply condition in function call Marko Rauhamaa <marko@pacujo.net> - 2015-03-28 09:50 +0200
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 20:17 +1100
                Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-28 03:19 -0600
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 20:57 +1100
                Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-30 09:35 +1100
                Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-30 00:46 +0200
          Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-26 20:25 -0600
            Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 19:46 -0700
    Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-26 07:27 +0100
      Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-26 18:06 +1100
        Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-27 21:02 +0100
          Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-28 09:55 +1100
      Re: Supply condition in function call Peter Otten <__peter__@web.de> - 2015-03-26 10:03 +0100
        Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-27 20:46 +0100
          Re: Supply condition in function call Peter Otten <__peter__@web.de> - 2015-03-27 21:38 +0100
  Re: Supply condition in function call smap <askme.first@thankyouverymuch.invalid> - 2015-03-28 08:58 +0000

csiph-web