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: 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" Date: Thu, 12 Jul 2012 15:29:42 +1000 From: John O'Hagan To: python-list@python.org Subject: Re: lambda in list comprehension acting funny In-Reply-To: References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, 11 Jul 2012 13:21:34 -0700 (PDT) John Ladasky 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