WestMidlands | SDC NOV 2025| Sara Tahir | Sprint 2 | Implement a Python Linked List#111
WestMidlands | SDC NOV 2025| Sara Tahir | Sprint 2 | Implement a Python Linked List#111SaraTahir28 wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
The code in linked_list_test.py expects both .next and .previous properties of the removed node to be assigned None. Currently your implementation could not pass the tests.
Note: Do you know the why it is a good practice to assign .next and .previous of the removed node to None?
| @@ -0,0 +1,55 @@ | |||
|
|
|||
| #each node should know what comes before it and what come after it | |||
| class node: | |||
There was a problem hiding this comment.
Why not name the class name in PascalCase?
There was a problem hiding this comment.
I have changed that to Node. Thanks
| #Remove last node | ||
| def pop_tail(self): | ||
| if self.tail is None: |
There was a problem hiding this comment.
Why not use docstring to describe the method?
Note: The indentation of the comment is a bit off.
| removed = self.tail | ||
| #checking for 1 elemt | ||
| if self.head == self.tail: | ||
| self.head = self.tail = None | ||
| return removed.value | ||
|
|
||
| #Greater than 1 element, move tailpointer to previos | ||
| self.tail = self.tail.previous | ||
| self.tail.next = None #cutting link to old tail | ||
| return removed.value |
There was a problem hiding this comment.
Could consider calling remove(removed) -- less code to maintain.
There was a problem hiding this comment.
Thanks for the suggestion. I updated pop_tail() to call remove(removed) so that all pointer‑manipulation logic lives in one place
…the node, all tests are passing
I have researched on how important it is to set .next and .previous to None to maintaine the integrity of the data structures, prevent bugs and make debugging easier because a removed node must not still point into the list. |
Learners, PR Template
Self checklist
Changelist
Questions
I have no Questions. Thanks.