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


Groups > comp.lang.python > #25199

Re: lambda in list comprehension acting funny

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <johnmohagan@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'argument': 0.04; 'remind': 0.05; 'definitions': 0.07; 'subject:skip:c 10': 0.07; 'python': 0.09; 'namespace': 0.09; 'retained': 0.09; 'library': 0.15; 'syntax,': 0.16; 'threads': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'sender:addr:gmail.com': 0.18; 'code.': 0.20; 'sort': 0.21; 'explicit': 0.22; 'example': 0.23; 'programming': 0.23; 'third-party': 0.23; "haven't": 0.23; 'pass': 0.25; 'header :In-Reply-To:1': 0.25; "doesn't": 0.28; 'lines': 0.28; 'subject:list': 0.28; '(unless': 0.29; 'concise': 0.29; 'function': 0.30; 'code': 0.31; 'received:209.85.160.46': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'clear': 0.35; 'so,': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'really': 0.36; 'modules': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'space': 0.39; 'header:Received:5': 0.40; 'john': 0.60; 'header:Message-Id:1': 0.62; 'friends:': 0.65; 'jul': 0.65; 'readers': 0.65; 'adhere': 0.84; 'drawer': 0.84; 'forced': 0.84; 'max,': 0.84; '(pdt)': 0.91; 'subject:funny': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=iaVvvAha5V/e5WqdyQ3ZnxZ/f9ArMDXPPfORKrBJlBw=; b=ouiv8VvKuChCSeiayvi5G3VGrkf3oKM8+CbkP5GMaLtXp01f7d3IrhsrtHm3TW/Z2m vbgqG4iiSE9YBVVU0SkJ56xMqZLciBWNVJBrJsywofa8et70x4wfI57xewc2gnF/Dg0t kkLqXhx7xHzJuKsuVk9GW6zZ2BJ3CYf237cBawfWrdKbJA8mfJ21zhBf2t6wYlFCzTiD ARDp71nSnt7JnqDH+404hk95zkSt1lPBEwUCZ6xg6UQ2nJDiQgf7K3pyVhe0zEnrhaXA mevHLWRmMB/mktLstfvc/L3kkCSQRxEIoiiTu9gcuDf94n8VisBFq2IQFobPGK4VHTwI DSGg==
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Thu, 12 Jul 2012 15:29:42 +1000
From John O'Hagan <research@johnohagan.com>
To python-list@python.org
Subject Re: lambda in list comprehension acting funny
In-Reply-To <c023034b-d23e-4392-b845-232f1ec35f05@googlegroups.com>
References <mailman.2006.1341988919.4697.python-list@python.org> <d390ef92-5316-422b-b180-5a944d33fd68@d6g2000pbt.googlegroups.com> <c023034b-d23e-4392-b845-232f1ec35f05@googlegroups.com>
X-Mailer Sylpheed 3.2.0beta9 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2025.1342070992.4697.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342070992 news.xs4all.nl 6848 [2001:888:2000:d::a6]:55829
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25199

Show key headers only | View raw


On Wed, 11 Jul 2012 13:21:34 -0700 (PDT)
John Ladasky <john_ladasky@sbcglobal.net> wrote:

> Exactly.  It's threads like these which remind me why I never use lambda.  I
> would rather give a function an explicit name and adhere to the familiar
> Python syntax, despite the two extra lines of code.  I don't even like the
> name "lambda".  It doesn't tell you what it is (unless you're John McCarthy),
> a function that you won't re-use and so you don't really need to give it a
> persistent name.  
> 
> I haven't seen any lambdas in any Python library code, or in any of the
> third-party modules I use (numpy, matplotlib, Biopython).  Do they exist?
> Because I have not been forced to do so, I haven't retained a space in the
> top drawer of my programming brain for lambda.
[...]

+1 about the name, -1 about the usefulness. For example it's a clear and
concise way to pass a key argument to min, max, sort and friends:

sort(seq, key=lambda x: x.a)

The alternative is to have trivial function definitions floating around the
namespace which readers of the code have to search for.

--
John

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


Thread

lambda in list comprehension acting funny Daniel Fetchinson <fetchinson@googlemail.com> - 2012-07-11 08:41 +0200
  Re: lambda in list comprehension acting funny "Colin J. Williams" <cjw@ncf.ca> - 2012-07-11 06:28 -0400
    Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-11 10:34 -0600
      Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 20:39 -0700
        Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:51 +0000
          Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 22:04 -0700
            Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 06:18 +0000
              Re: lambda in list comprehension acting funny Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-12 08:40 +0100
      Re: lambda in list comprehension acting funny 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-11 20:39 -0700
  Re: lambda in list comprehension acting funny woooee <woooee@gmail.com> - 2012-07-11 11:38 -0700
    Re: lambda in list comprehension acting funny John Ladasky <john_ladasky@sbcglobal.net> - 2012-07-11 13:21 -0700
      Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 00:52 +0000
      Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-11 21:05 -0400
        Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:53 +0000
          Re: lambda in list comprehension acting funny Terry Reedy <tjreedy@udel.edu> - 2012-07-12 00:24 -0400
          Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-12 00:39 -0400
            Re: lambda in list comprehension acting funny Robert Miles <robertmiles@teranews.com> - 2012-08-15 19:26 -0500
      Re: lambda in list comprehension acting funny John O'Hagan <research@johnohagan.com> - 2012-07-12 15:29 +1000
      Re: lambda in list comprehension acting funny Robert Kern <robert.kern@gmail.com> - 2012-07-12 10:06 +0100
    Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-12 00:22 +0200
    Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-11 23:47 +0000
      Re: lambda in list comprehension acting funny Daniel Fetchinson <fetchinson@googlemail.com> - 2012-07-12 04:54 +0200
  Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-12 03:59 +0000
    Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-12 10:53 -0600
    Re: lambda in list comprehension acting funny Rotwang <sg552@hotmail.co.uk> - 2012-07-12 18:23 +0100
      Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 02:20 +0000
  Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-12 21:33 -0700
    Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 06:36 +0000
      Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 06:44 -0700
        Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 07:45 -0700
        RE: lambda in list comprehension acting funny "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 16:12 +0000
          Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 09:46 -0700
            Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-14 03:20 +1000
          Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-13 19:53 +0200
            RE: lambda in list comprehension acting funny "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 18:06 +0000
            Re: lambda in list comprehension acting funny Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-13 12:54 -0600
              Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-13 21:26 +0200
              Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 23:29 +0000
                Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-15 10:49 +1000
                Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-15 08:32 +0000
                Re: lambda in list comprehension acting funny Chris Angelico <rosuav@gmail.com> - 2012-07-15 18:44 +1000
                Re: lambda in list comprehension acting funny Hans Mulder <hansmu@xs4all.nl> - 2012-07-15 21:25 +0200
                Re: lambda in list comprehension acting funny Terry Reedy <tjreedy@udel.edu> - 2012-07-15 06:27 -0400
            Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 19:31 -0700
              Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 03:43 +0000
                Re: lambda in list comprehension acting funny rusi <rustompmody@gmail.com> - 2012-07-13 21:53 -0700
                Re: lambda in list comprehension acting funny Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 07:46 +0000
        Re: lambda in list comprehension acting funny Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-13 13:47 -0400

csiph-web