Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'subject:skip:c 10': 0.07; 'python': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'contribute': 0.10; 'def': 0.10; 'b):': 0.16; 'funcs': 0.16; 'parentheses': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'code.': 0.20; 'cc:2**0': 0.23; '>': 0.23; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'subject:list': 0.28; 'no,': 0.29; 'thursday,': 0.30; 'expect': 0.31; '11,': 0.33; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; '12,': 0.36; "i'll": 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'help': 0.40; 'july': 0.60; 'jul': 0.65; '81,': 0.84; 'original.': 0.84; 'subject:funny': 0.91 Newsgroups: comp.lang.python Date: Wed, 11 Jul 2012 20:39:45 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.83.145 MIME-Version: 1.0 Subject: Re: lambda in list comprehension acting funny From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: Python 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: , Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342064389 news.xs4all.nl 6840 [2001:888:2000:d::a6]:58196 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25191 On Thursday, July 12, 2012 12:34:33 AM UTC+8, Ian wrote: > On Wed, Jul 11, 2012 at 4:28 AM, Colin J. Williams <cjw@ncf.ca> 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. I'll contribute my way of python programming: def powerb(x, b): # return x**b One functor is enough!