Skip to content

London | 26-SDC-Mar | beko | Sprint 2 | implement a linked list in py…#195

Open
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-implement-linked-list-in-Python
Open

London | 26-SDC-Mar | beko | Sprint 2 | implement a linked list in py…#195
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-implement-linked-list-in-Python

Conversation

@Abubakar-Meigag

Copy link
Copy Markdown

…thon

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Completed implementing a linked list in python

@Abubakar-Meigag Abubakar-Meigag added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Jun 30, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good.

Comment on lines +4 to +8
class _Node:
def __init__(self, value):
self.value = value
self.next: Optional["_Node"] = None
self.prev: Optional["_Node"] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest exploring the use of __slots__ to reduce memory usage?

Comment on lines +45 to +62
def remove(self, node):
if node == self.head:
self.head = node.next
if self.head:
self.head.prev = None
else:
self.tail = None

elif node == self.tail:
self.tail = node.prev
if self.tail:
self.tail.next = None
else:
self.head = None

else:
node.prev.next = node.next
node.next.prev = node.prev

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you look up why, in a doubly linked List implementation, assigning .next and .previous of the removed node to None a good practice?

No change required.

Comment on lines +35 to +41
if self.head == self.tail:
self.head = None
self.tail = None
else:
self.tail = self.tail.prev
if self.tail:
self.tail.next = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also consider removing the tail by calling remove().

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants