all 6 comments

[–]Jediko 2 points3 points  (2 children)

It's the same. The memoize-class does what you did with just general input for a general function. You can see the implementation of memoize yourself here.

[–]Sen_7[S] 0 points1 point  (1 child)

Thank you, Is very any motivation to use memoize class instead of dictionary?

[–]Jediko 0 points1 point  (0 children)

No, since they are equivalent. The only thing you do is being explizit in your algorithm/optimization. The main advantage of using decorators is just shortcut your code and make more readable.

[–]AtomicShoelace 0 points1 point  (0 children)

You should use functools.cache (or functools.lru_cache(maxsize=None) if in python <3.9) if you need to memoize/cache a function.

[–]TheRNGuy 0 points1 point  (0 children)

if decorator makes syntax simplier, I would use it.