advanced listcomprehenions?

Ivan Illarionov ivan.illarionov at gmail.com
Fri Jun 20 10:27:06 CEST 2008


On 20 июн, 11:31, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> Terry Reedy <tjre... at udel.edu> wrote:
> >> [['Fizz', 'Buzz', 'FizzBuzz', str(i)][62/(pow(i, 4, 15) + 1)%4] for i
> >> in xrange(1, 101)]
>
> > These make the lookup table variable, so it has to be recalculated for
> > each i.
>
> So what? Mark Wooding was posting about mathematical elegance and came up
> with that really neat pow() call. If runtime came into it then one of the
> previous solutions or (as Mark already said) a straightforward sometable[i%
> 15] is going beat something like this hands-down.
>
> This is coding for fun not profit.
>
> --
> Duncan Boothhttp://kupuguy.blogspot.com

I can't resist...
[[i,"Fizz","Buzz","FizzBuzz"][(not i%3)+(not i%5)*2] for i in range(1,
101)]

Ivan



More information about the Python-list mailing list