NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | implement_lru_cache#169
NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | implement_lru_cache#169TzeMingHo wants to merge 2 commits into
Conversation
| def set(self, key, value): | ||
| if key in self.dict: | ||
| self.dict[key].value = value | ||
| self.get(key) |
There was a problem hiding this comment.
With the current approach of moving a node to the front:
- It is not immediately obvious why this method calls
get() - Calling
get()introduces an additional (but unnecessary) dictionary lookup
Could you explore a cleaner way to structure the code?
cjyuan
left a comment
There was a problem hiding this comment.
Have you also looked up "Best practices about using __slot__" to learn more about it?
Changes look good. Well done.
| def __init__(self, key, value): | ||
| self.key = key | ||
| self.value = value |
There was a problem hiding this comment.
Making each node to keep two values (key and value) would make the linked list less attractive (because most uses of linked list only needs to store one value in each node).
Could you describe how you would implement the LRU cache if you were to import your linked list implemented in the other exercise (unmodified)?
No change needed
|
Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
1.1 Accepts a key, a value in the class Node
1.2 Methods in class LinkedList accept Node