Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FizzBuzz implementation
class FizzBuzz:
def display(self):
return map(lambda n: ['fizz', 'buzz', 'fizzbuzz', n][[(True, False), (False, True), (True, True), (False, False)].index((n%3 == 0, n%5 == 0))], range(1,21))
import unittest
from fizzbuzz import FizzBuzz
class TestFizzBuzz(unittest.TestCase):
def test_display(self):
fizzBuzz = FizzBuzz()
self.assertEqual([1, 2, "fizz", 4, 'buzz', "fizz", 7, 8, "fizz", 'buzz', 11, "fizz", 13, 14, "fizzbuzz", 16, 17, "fizz", 19, 'buzz'], fizzBuzz.display())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment