Last active
September 10, 2015 20:10
-
-
Save uskudnik/453eb26e3ef352c76d6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
# take 1 | |
def abczzz(limit, abc={3: "fizzz", 5: "buzzz"}): | |
d = defaultdict(str) | |
table = [] | |
for k, v in abc.items(): | |
table += [{k*x:v for x in range(limit)}] | |
for t in table: | |
for k, v in t.items(): | |
d[k] += v | |
return [d.get(x, x) for x in range(limit)] | |
# one liner | |
[dict(filter(lambda x: x[1], {i: "".join(map(lambda x: x.get(i, ""), [{x-1:v for x in range(1, limit, k)} for k,v in abc.items()])) for i in r}.items())).get(x, x) for x in range(1, limit)] | |
# shortest | |
a={3:"fizz", 5:"buzz"} | |
def fb(n, a): | |
r=range(n) | |
t=defaultdict(str) | |
for k in iter(a): | |
for x in r[::k]: | |
t[x] += a[k] | |
return [t.get(x, x)for x in r[1:]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment