python generator cheat sheet code example
Example 1: python generator cheat sheet download
from functools import wraps
def debug(print_result=False):
def decorator(func):
@wraps(func)
def out(*args, **kwargs):
result = func(*args, **kwargs)
print(func.__name__, result if print_result else '')
return result
return out
return decorator
@debug(print_result=True)
def add(x, y):
return x + y
Example 2: python generator cheat sheet download
>>> multiply_by_3 = get_multiplier(3)
>>> multiply_by_3(10)
30