Repository navigation
London | 26-Jul-SDC |Shaghayegh far | Sprint 2 | Implement a linked list - #245
shaghayeghfar wants to merge 2 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Could consider adding type hints to each method to clearly specify the types of its parameters and return value.
| class Node: | ||
| def __init__(self, value): | ||
| self.value = value | ||
| self.next = None | ||
| self.previous = None |
There was a problem hiding this comment.
May I suggest exploring the use of __slots__ to reduce memory usage?
| if self.head == self.tail: | ||
| self.head = None | ||
| self.tail = None | ||
| else: | ||
| self.tail = self.tail.previous | ||
| self.tail.next = None |
There was a problem hiding this comment.
Could consider delegating the node removing task to remove() -- less code to maintain.
|
Dear @cjyuan , |
| self.previous = None | ||
| __slots__ = ("value", "next", "previous") | ||
|
|
||
| def __init__(self, value: str) -> None: |
There was a problem hiding this comment.
Limiting the value to be of type str would make the linked list less flexible -- could not be reused for different typesof data.
Suggestion: Explore the topic "Generics" in Python. You could ask AI this:
In Python, how to ensure a parameter (and its storage) maintains a consistent type
$T$ throughout a class?
Note: Python 3.12+ introduce a new syntax which make specifying generic type easier.
No change needed
Learners, PR Template
Self checklist
Task code
CYF-1180
Changelist
Implemented a linked list in Python with push_head, pop_tail, and remove. All tests passed.