Advertisement
Guest User

Untitled

a guest
Oct 24th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. from functools import wraps
  2.  
  3.  
  4. def hash_deco(func):
  5.     hash_dict={}
  6.  
  7.     @wraps(func)
  8.     def wrappper(*args, **qwargs):
  9.         res = func(*args, **qwargs)
  10.         print(f"Heshing result {func.__name__}")
  11.         key = hash(*args, **qwargs)
  12.         hash_dict[key] = res
  13.         print(hash_dict)
  14.  
  15.         return res
  16.  
  17.     return wrappper
  18.  
  19.  
  20. @hash_deco
  21. def fun(x):
  22.     x = x + 1
  23.     return x
  24.  
  25.  
  26.  
  27. print(fun(5))
  28. print(fun(10))
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement