Python presentations

88888 Dihedral dihedral88888 at googlemail.com
Fri Sep 14 01:57:54 EDT 2012


Chris Angelico於 2012年9月14日星期五UTC+8上午6時39分25秒寫道:
> On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne <news at blinne.net> wrote:
> 
> > On 13.09.2012 21:01, 88888 Dihedral wrote:
> 
> >> def powerlist(x, n):
> 
> >>     # n is a natural number
> 
> >>      result=[]
> 
> >>      y=1
> 
> >>      for i in xrange(n):
> 
> >>         result.append(y)
> 
> >>         y*=x
> 
> >>      return result # any object in the local function can be returned
> 
> >
> 
> > def powerlist(x, n):
> 
> >     result=[1]
> 
> >     for i in xrange(n-1):
> 
> >         result.append(result[-1]*x)
> 
> >     return result
> 
> >
> 
> > 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)]
> 
> 
> 
> But you're responding to a bot there. Rather clever as bots go, though.
> 
> 
> 
> ChrisA

I do not object the list comprehension in concept. 
But I have to convert python code to cython from time to time.

Well, this imposes some coding style definitely.
 





More information about the Python-list mailing list