Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.162 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.70; '*S*': 0.02; 'subject:skip:c 10': 0.07; 'received:mail-qc0-f174.google.com': 0.09; 'funcs': 0.16; 'lambda': 0.16; 'simplest': 0.16; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'print': 0.32; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'does': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'more': 0.63; 'importantly,': 0.65; 'down!': 0.84; 'to:name:python': 0.84; 'why?': 0.84; 'subject:funny': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=SOglRru7upYq+yM14kLx4wjoAFbMBLvzdO3+RiBT1KI=; b=VrT3e1J/RPhoFfmrL8aGWWqbEgGGLB4BsJy1+4+ImewLiXJ+tRMcaebwYtRaCLvFXh HmbBFtzjEL7Gaeu6fQ1faqkfmRzaVxLwQlBUzLytE5qKTlO8ClYZX7KWDWj3jOUHw6wq WFpNXelqLnHtSl20sozcrlIRtAShFdLjo9KJEtYBPZaldRmz6utVS7BME3cI+V4gmlvB a+UVjyNiPzXTdc19Ekt9rZnm1/JTiKJGBZbFnnBgoqxyCwtEWBIO8T4FltTGmh3WZLNt M9bSkNaVRN8wmY1LYbnkR8WBUptTmCPu0213q0uiCwUrE9EVxxD+M3WwVOzOo82/c2Rm 0Ueg== MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 11 Jul 2012 08:43:11 +0200 Subject: Re: lambda in list comprehension acting funny From: Daniel Fetchinson 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341988993 news.xs4all.nl 6969 [2001:888:2000:d::a6]:33404 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25167 > funcs = [ lambda x: x**i for i in range( 5 ) ] > print funcs[0]( 2 ) > print funcs[1]( 2 ) > print funcs[2]( 2 ) > > This gives me > > 16 > 16 > 16 > > When I was excepting > > 1 > 2 > 4 > > Does anyone know why? And more importantly, what's the simplest way to achieve the latter? :) -- Psss, psss, put it down! - http://www.cafepress.com/putitdown