Created
October 5, 2012 18:08
-
-
Save ryancdotorg/3841403 to your computer and use it in GitHub Desktop.
Extended FizzBuzz in Python
This file contains hidden or 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
#!/bin/env python | |
# Needs python 2.7 or later | |
from collections import OrderedDict | |
substitutions = OrderedDict([(3, 'Fizz'), (5, 'Buzz'), (7, 'Quxx')]) | |
for i in xrange(1, 128): | |
line = '' | |
# This depends on the ordering of keys in the dict | |
for n in substitutions.keys(): | |
if i % n == 0: | |
line += substitutions[n] | |
print line or i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment