Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'variable,': 0.07; 'line:': 0.09; 'naturally': 0.09; 'skip:[ 30': 0.09; 'written': 0.14; 'am,': 0.14; 'wrote:': 0.14; 'lambda': 0.16; 'local.': 0.16; 'promoted': 0.16; 'tue,': 0.17; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'seems': 0.21; 'received:209.85.161.46': 0.23; 'received:mail-fx0-f46.google.com': 0.23; 'received:209.85.161': 0.26; 'message-id:@mail.gmail.com': 0.28; 'variables': 0.29; 'binding': 0.30; 'preferable': 0.30; 'separate': 0.31; 'to:addr :python-list': 0.33; 'there': 0.35; 'change,': 0.35; 'recognize': 0.35; 'couple': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'ways': 0.37; 'two': 0.37; 'problem.': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'sometimes': 0.39; "i'd": 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'more': 0.60; '31,': 0.65; 'as:': 0.71; '12:48': 0.84; 'technique': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=XafB6En2Rm+mrLflzXV9wwra7QdKcijscKVA1PGkfWs=; b=olmYpAGHDblcPLhBAe34FvyYxrxevVNuCPzM5CRX96CXmm7LVsYSPb9NqHIeUiyufW PcYr8Fo1tHtJ4ZYXRLwekFsk5YtnorJTGhdM/L2B8qgKwuua1U1pnXfXlaFWCtQU7WJa BHGzn/EbCcpwZQFFQvmN5PFqaY3Rq4DPcgOrI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=l+07UKViZ8sk42rYzEkIjbOSB+Jvg8acfJneaJM8H6XpH1ybO0zoXMcTVdUsC+qyvs fcbiu4Taqwv/I+WQ8zpBanv8WGFd5TUa+bVJMRqMZHyvqIIiHPnT98Gcg4VVVpStXyPp 3nJTHsc/lX583KVb49F2m1bOETzxv+bkhUjQA= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Tue, 31 May 2011 01:35:27 -0600 Subject: Re: Something is rotten in Denmark... To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 82.94.164.166 X-Trace: 1306827358 news.xs4all.nl 49179 [::ffff:82.94.164.166]:46194 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6714 On Tue, May 31, 2011 at 12:48 AM, harrismh777 wro= te: > =A0 =A0 What is going on with the binding in the first construct... this = seems > to reduce the usefulness of lambda to a considerable extent? I don't see why; as you've shown there are a couple of simple ways to avoid this problem. The trick is just to recognize that when you have a closure around a variable, and that variable needs to change, but the value in the closure needs to be constant, then what you really need are two separate variables -- the cell variable needs to be promoted to a local. How you accomplish that is not terribly important. One other technique that is sometimes preferable is functools.partial, e.g.= : fs =3D [functools.partial(operator.add, i) for i in range(10)] Tangentially, I'd like to point out that this line: [fs[i](1) for i in range(10)] is more naturally written as: [f(1) for f in fs]