Last active
August 29, 2015 14:25
-
-
Save tomoh1r/9a7b9cf9e937a7c0fc68 to your computer and use it in GitHub Desktop.
15個 fizz/buzz のリスト作ってから yield で fizzbuzz
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def fizzbuzz(): | |
loop = [ | |
None, | |
None, | |
'fizz', | |
None, | |
'buzz', | |
'fizz', | |
None, | |
None, | |
'fizz', | |
'buzz', | |
None, | |
'fizz', | |
None, | |
None, | |
'fizzbuzz', | |
] | |
idx = 0 | |
count = 1 | |
while True: | |
if idx == 15: | |
idx = 0 | |
yield loop[idx] or count | |
idx += 1 | |
count += 1 | |
if __name__ == '__main__': | |
count = 20 | |
g = fizzbuzz() | |
print([next(g) for _ in range(count)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment