Skip to content

Instantly share code, notes, and snippets.

View raymondng76's full-sized avatar
🥺

Raymond raymondng76

🥺
  • AI Singapore
  • Singapore
View GitHub Profile
@raymondng76
raymondng76 / Decorators Example
Created August 9, 2020 13:08
Decorators Example #python #decorator
# Decorators using the @ symbol ##########
def double_args(func):
def wrapper(a, b):
return func(a * 2, b * 2) # Modify input arguments before passing to requested function
return wrapper
@double_args # This is to indicate the decorators is used on the multiple function
def multiple(a, b):
return a * b
@raymondng76
raymondng76 / Memoize_Example
Last active June 6, 2022 08:22
Memoize Example #python #memoize
# Memoize example which stores results for fast look ups
import time
def memoize(func):
cache = {}
def wrapper(*args, **kwargs):
if (args, kwargs) not in cache:
cache[(args, kwargs)] = func(*args, **kwargs)
return cache[(args, kwargs)]