Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created October 5, 2012 18:08
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 ryancdotorg/3841403 to your computer and use it in GitHub Desktop.
Save ryancdotorg/3841403 to your computer and use it in GitHub Desktop.
Extended FizzBuzz in Python
#!/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