Skip to content

Instantly share code, notes, and snippets.

@diogojorgebasso
Created December 25, 2020 14:03
Show Gist options
  • Save diogojorgebasso/b045cbbc16f122215ea97e5e2e603424 to your computer and use it in GitHub Desktop.
Save diogojorgebasso/b045cbbc16f122215ea97e5e2e603424 to your computer and use it in GitHub Desktop.
Let's create the HackerRank example "FizzBuzz" with decorators in Python!
def fizz_buzz_generator(function):
def wrapper(): #standar name
func = function()
lista =[]
for x in range(1,func+1):
if x%3==0 and x%5==0 :
lista.append("FizzBuzz")
elif x%5==0:
lista.append("Buzz")
elif x%3==0:
lista.append("Fizz")
else:
lista.append(0)
return lista
return wrapper
@fizz_buzz_generator
def number_fizzbuzz_wanted():
return 15
number_fizzbuzz_wanted()
@diogojorgebasso
Copy link
Author

diogojorgebasso commented Dec 25, 2020

I'm not quite getting the lambda function for this example. If someone wants to contribute, feel free to comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment