Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'suppose': 0.07; 'sep': 0.09; 'def': 0.10; 'alexander': 0.16; 'comp': 0.16; 'err,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inclined': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'skip': 0.17; '>>>': 0.18; "i'd": 0.22; 'needed.': 0.23; 'header:In-Reply-To:1': 0.25; '(see': 0.27; '[1]': 0.27; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'there.': 0.28; 'chris': 0.28; 'fri,': 0.30; 'function': 0.30; 'more,': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'clear': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'more': 0.63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Tf3Ntr2iEyIn60Mangk3NBXPpGCHf3nl0WqH9zOt1Ps=; b=aiWClxYK/Qnkx1jP6F6Ln5Fu/+zgKidQcHicD3VR4Engffb79yPm5E3drkfIiD7Bzl WNYLSzl/8FVoT/maGrPdcaYWkpuvcTwIP97RpO5g4VOo+WDpvDxMOlF3Tf7oOlvDjp3M bzvNzKprGECKEdR0z62xbaJccWr/VSv/zLVTmBZsyQzQQYjA8HeA4bKdVMiFs/OEH6m5 MHiDQ5zQermdO+pIyOhmwYB7H75q+NtDmIkGKhaVtM+VADpbl43vur2O5i4OX23ngm1z BhaujCzqqE+WbaOPFCyLggzAfjqNx5r89r1L5YF88mNz8M4PZgDhVmRORXNgss//SuBy j51w== MIME-Version: 1.0 In-Reply-To: <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> References: <06a1a81b-246b-4e7b-ba34-4701f46889c8@googlegroups.com> <50525f48$0$6573$9b4e6d93@newsspool3.arcor-online.net> <5053196e$0$6578$9b4e6d93@newsspool3.arcor-online.net> Date: Fri, 14 Sep 2012 22:19:22 +1000 Subject: Re: Python presentations From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347625166 news.xs4all.nl 6879 [2001:888:2000:d::a6]:34623 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29161 On Fri, Sep 14, 2012 at 9:47 PM, Alexander Blinne wrote: > On 14.09.2012 00:38, Chris Angelico wrote: >> On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne wrote: >>> def powerlist(x,n): >>> if n==1: >>> return [1] >>> p = powerlist(x,n-1) >>> return p + [p[-1]*x] >> >> Eh, much simpler. >> >> def powerlist(x,n): >> return [x*i for i in xrange(n-1)] > > I suppose you meant: > > def powerlist(x,n): > return [x**i for i in xrange(n-1)] > > But this is less efficient, because it needs more multiplications (see > Horner's method) Err, yes, I did mean ** there. The extra multiplications may be slower, but which is worse? Lots of list additions, or lots of integer powers? In the absence of clear and compelling evidence, I'd be inclined to go with the list comp - and what's more, to skip this function altogether and use the list comp directly where it's needed. ChrisA