Skip to content

NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | implement_lru_cache#169

Open
TzeMingHo wants to merge 2 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/implement_lru_cache
Open

NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | implement_lru_cache#169
TzeMingHo wants to merge 2 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/implement_lru_cache

Conversation

@TzeMingHo

@TzeMingHo TzeMingHo commented Jun 17, 2026

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  1. Borrowed the linked list from the previous exercise and made some updates
    1.1 Accepts a key, a value in the class Node
    1.2 Methods in class LinkedList accept Node
  2. Created class LruCache
  3. Created methods: get, set, and a helper function move_to_front in class LruCache
  4. Added slots for classes

@TzeMingHo TzeMingHo added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 17, 2026
def set(self, key, value):
if key in self.dict:
self.dict[key].value = value
self.get(key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 18, 2026
@TzeMingHo TzeMingHo added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 20, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you also looked up "Best practices about using __slot__" to learn more about it?

Changes look good. Well done.

Comment on lines +4 to +6
def __init__(self, key, value):
self.key = key
self.value = value

@cjyuan cjyuan Jun 21, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants