London | 25-SDC-July | Fatma Arslantas | Sprint 2 | Implement an LRU cache in Python #75
+37
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
I implemented an LRU Cache in Python.
OrderedDictfrom the Python collections library.OrderedDictworks like a dictionary but remembers the order of items. This helps us achieve O(1) speed.get(key): Returns the value and moves the item to the end (marks it as recently used).set(key, value): Adds a new item. If the cache is full (limitreached), it removes the first item (the oldest one).limitis 0 or less.Questions
I don’t have any questions, thank you!