Advertisement
here2share

# lru_cache.py

Jul 9th, 2023
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. # lru_cache.py
  2.  
  3. from functools import lru_cache
  4.  
  5. @lru_cache(maxsize=None) # lru = "least recently used"
  6. def increment(num):
  7.     print("Running 1000 lines of code")
  8.     return num
  9.  
  10. print(increment(1))
  11. print(increment(2))
  12. print(increment(3))
  13. print(increment(2))
  14. print(increment(1))
  15. print(increment(3))
  16.  
  17. '''
  18. Running 1000 lines of code
  19. 1
  20. Running 1000 lines of code
  21. 2
  22. Running 1000 lines of code
  23. 3
  24. 2
  25. 1
  26. 3
  27. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement