Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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