Repository navigation
Conversation
| #node class to hold value and pointer | ||
| class Node: | ||
| def __init__(self,data): | ||
| self.data = data | ||
| self.next = None # pointer to next node | ||
| self.prev = None # pointer to previous node |
There was a problem hiding this comment.
-
Common practice is to keep a spacing between parameters. Prettier does not support Python, you would probably need to install a different formatter for Python.
-
Could consider using docstrings instead of comments do document a class/function.
-
May I suggest exploring the use of
__slots__to reduce memory usage?
| def push_head(self,data): | ||
| new_node = Node(data) | ||
|
|
||
| if not self.head: #if the node is empty it will have both head & tail |
There was a problem hiding this comment.
-
The condition could also evaluate to
Trueifself.headisFalse. Could you look up a more suitable and preferred syntax to check if a value isNone? -
A small suggestion: try to avoid comments that simply restate what the code already makes clear. In this case, the code is self-explanatory, so the comment doesn't really add any new information. Comments are most useful when they explain why something is done, clarify non-obvious behaviour, or document an important assumption. This helps keep the code clean and makes the comments that we do have more valuable.
| if self.head == self.tail: | ||
| self.head = None | ||
| self.tail = None | ||
| else: | ||
| self.tail = self.tail.prev | ||
| self.tail.next = None |
There was a problem hiding this comment.
Could consider delegating the node removing task to remove() -- less code to maintain.
|
Note: The PR description is missing a Changelist section. |
Self checklist
Task code
CYF-1180
Hello!
Thank you for your time. Please help me by checking the code for the implementation of LinkedList in Python.
Kindly provide feedback.
Thanks,
AYK