London | 25-SDC-Nov | Emiliano Uruena | Sprint 2 | LRU-cache Python#133
London | 25-SDC-Nov | Emiliano Uruena | Sprint 2 | LRU-cache Python#133Emilianouz wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
To better adhere to the Single-Responsibility Principle (SRP) from SOLID design principles,
it's preferable to implement the "doubly linked list" and the "LRU Cache" as separate classes, with the linked list used inside LruCache to manage ordering.
In fact, you can import your LinkedList class from the other exercise, and then store each key-value pairs as a tuple.
Alternatively, you can use OrderedDict directly within LruCache to maintain order.
Could you update your code using one of these approaches?
I've implemented by storing key/value in a Node class. LMKWYT. Thank you. |
cjyuan
left a comment
There was a problem hiding this comment.
Code is working.
Formatting is not quite consistent. e.g.
- Line 63: no space after '
,in parameter list - Line 62, 75: No space after
#
You can install a formatter extension in VSCode and enable "Format on save" to keep all code formatted consistently automatically. (Note: Python formatter extension requires Python runtime to work in VSCode.)
| class Node: | ||
| def __init__(self, key, value): | ||
| self.key = key | ||
| self.value = value | ||
| self.previous = None | ||
| self.next = None |
There was a problem hiding this comment.
You could also just import the linked list class you implemented in the other exercise and then store key-value pair as a tuple.
Self checklist
Changelist
Implement LRU Cache functionality.