Repository navigation
NW| 26-Jul-SDC | Ahmad Hmedan | Sprint 2 | Implement a linked list in Python - #227
AhmadHmedann wants to merge 4 commits into
Conversation
| @@ -0,0 +1,60 @@ | |||
| class LinkedList: | |||
| class clsNode: | |||
There was a problem hiding this comment.
Suggestion: Look up "Python naming convention for inner class"?
| def __init__(self, value): | ||
| self.next = None | ||
| self.previous = None | ||
| self.value = value |
There was a problem hiding this comment.
May I suggest exploring the use of __slots__ to reduce memory usage?
There was a problem hiding this comment.
Thank you for the suggestion. I've added __slots__ to reduce memory usage.
| if self.head == self.tail: | ||
| self.head = None | ||
| self.tail = None | ||
| self.size -= 1 | ||
| return removed_value | ||
| self.tail = self.tail.previous | ||
| self.tail.next = None | ||
| self.size -= 1 |
There was a problem hiding this comment.
-
The
.nextand.previouswere cleared when a node is removed inremoved()but not in this method. (Inconsistency) -
You could consider delegating the node removing task to
remove()-- less code to maintain.
There was a problem hiding this comment.
Thank you for the feedback. I've updated pop_tail() to reuse the existing remove() method
| __slots__ = ("next","previous","value") | ||
|
|
||
| def __init__(self, value): |
There was a problem hiding this comment.
In terms of code formatting, the spacing around the , in the parameter list is not consistent.
Prettier won't work for Python, so you may need to install different formatting tools for Python.
Learners, PR Template
Self checklist
Task code
CYF-1180
Changelist
Implemented a LinkedList class with push_head, pop_tail, and remove methods.