osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I really liked this Javscript FizzBuzz can it be as nice in Python?


Wow in both of these examples I have no idea what is happening. Enjoying trying to figure it out :-)

> print(*[[n,"Fizz","Buzz","Fizzbuzz"][int("300102100120100"[n%15])] for 
> n in range(1,101)], sep="\n") 

> This is not good code, and if anyone asks, I didn't say you were 
> allowed to do this in an interview. 

Sorry too late that was yesterday, they loved it :-)

> Here's some itertools gymnastics ;)
> 
> from itertools import *
> 
> def make(s, n):
>     return cycle(chain(repeat("", n-1), (s,)))
> 
> fizzbuzz = map("".join, zip(make("Fizz", 3), make("Buzz", 5)))
> 
> for i, fb in enumerate(islice(fizzbuzz, 100), 1):
>     print(fb or i)

Thanks 

Sayth