Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # lru_cache.py
- from functools import lru_cache
- @lru_cache(maxsize=None) # lru = "least recently used"
- def increment(num):
- print("Running 1000 lines of code")
- return num
- print(increment(1))
- print(increment(2))
- print(increment(3))
- print(increment(2))
- print(increment(1))
- print(increment(3))
- '''
- Running 1000 lines of code
- 1
- Running 1000 lines of code
- 2
- Running 1000 lines of code
- 3
- 2
- 1
- 3
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement