Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.073 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.01; '16,': 0.03; 'subject:skip:c 10': 0.07; 'funcs': 0.16; 'parentheses': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'code.': 0.20; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'no,': 0.29; 'expect': 0.31; '11,': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'jul': 0.65; '81,': 0.84; 'original.': 0.84; 'to:name:python': 0.84; 'subject:funny': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=90kDawFT76x+6I9uDqtPkoWZpA+/uVSJhF93J8WcjW0=; b=oC+fPJpuLr/O9z7wFJwy2k89fheL9b0TzS6aOBjpGZClGGO01aqr5ANIqVeHF7XJTi 3U8K6Rx3OHJxAOwqeBhgTIRxDPjQHnz0caLeJAE84brSJMSLWI9QzjDiEhiKIS1KGZRp uq3Y+4ef3gHm16SFtH1k3MfBOXxM9pg1Lre9MlDE1yBHjhotK80bZiSaUXvA7fTqHnxL JaEOkLq4F26qwO3Y511X1aW9/HFhQHuNRHL16D00ryXVvkt3UwepLH+Bn+SsZF32OQNp fnZOcHKJqy04ssqvqRXi430aATsgeKjpjA57rX3FGpGhi4h9t0AkCaWcb+8xdqcAPHT1 N4Ag== MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Wed, 11 Jul 2012 10:34:33 -0600 Subject: Re: lambda in list comprehension acting funny To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342024513 news.xs4all.nl 6911 [2001:888:2000:d::a6]:33691 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25176 On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams wrote: > I don't understand why you would expect 1, 2, 4. Because: funcs[0](2) == 2 ** 0 == 1 funcs[1](2) == 2 ** 1 == 2 funcs[2](2) == 2 ** 2 == 4 > Perhaps parentheses will help the order of evaluation: > > funcs = [(lambda x: x**i) for i in range( 5 )] > > This gives: > 1 > 16 > 81 No, that gives 16, 16, 16 just like the original. I don't understand why you would expect 1, 16, 81, unless you have misread the code.