Skip to content

Instantly share code, notes, and snippets.

@tomoh1r
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoh1r/9a7b9cf9e937a7c0fc68 to your computer and use it in GitHub Desktop.
Save tomoh1r/9a7b9cf9e937a7c0fc68 to your computer and use it in GitHub Desktop.
15個 fizz/buzz のリスト作ってから yield で fizzbuzz
#! /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