Hacker News new | past | comments | ask | show | jobs | submit login

They added a memoize decorator: https://docs.python.org/3.9/library/functools.html#functools...

Pretty useful for DP interview questions when implementing top down.




While nice, this isn't new. This is just a convenience for 'lru_cache(maxsize=None)'. lru_cache has been supported since Python 3.2.

See: https://docs.python.org/3.2/library/functools.html#functools...


They do mention that it’s more efficient than lru_cache, which isn’t surprising since cache is a lot simpler (just throw all the values in a dict keyed by the args).


No they are saying it's more efficiently that lru_cache with a finite maxsize. Implementation-wise it's identical to using maxsize=None. See source: https://github.com/python/cpython/blob/3.9/Lib/functools.py#...


It says it's more efficient than lru_cache with a size specified, it doesn't say that it's more efficient than lru_cache without one.


I find it weird that they called it `cache` instead of `cached` which would be more in line with `cached_property`. One of my colleagues already tripped over this today when he told me about this new feature.


They wanted to match `@functools.lru_cache`


Well one is a type of property and the other is saying cache what I'm decorating


Python has a lot of weird naming choices. Heck, they didn’t even Putin underscore in their new string method `removeprefix`


They won't let you use it in the interviews.


Oh sure, now they implement it, now that I've written my own so many times...

(This is a great addition and I'm very excited for it. Just a little sore haha.)


As others have stated, functools.lru_cache has existed for quite some time.


Never realized you could turn off the maximum size in the `lru_cache`, actually. Maybe I'll have to read those docs more carefully haha.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: