⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@Droid-An
Copy link

Learners, PR Template

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

Changelist

Implemented a linked list in Python.

Questions

no questions

@Droid-An Droid-An added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 13, 2025

def push_head(self, element):
node = Node(element)
if self.head and self.tail:
Copy link

Choose a reason for hiding this comment

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

Is it necessary to check also self.tail?

node.next = self.head
self.head.previous = node
self.head = node
elif not self.head and not self.tail:
Copy link

Choose a reason for hiding this comment

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

This line could probably be simplified.

Comment on lines +29 to +41
if self.head != node and self.tail != node:
node.previous.next = node.next
node.next.previous = node.previous
node.previous, node.next = None, None
elif self.head == node and self.tail != node:
node.next.previous = None
self.head = node.next
node.previous, node.next = None, None
elif self.head != node and self.tail == node:
node.previous.next = None
self.tail = node.previous
node.previous, node.next = None, None
elif self.head == node and self.tail == node:
Copy link

Choose a reason for hiding this comment

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

The conditions can be simplified (reduce the amount of checking needed) as:

   if self.head == node:
      if self.tail == node:
        # Case 1: head == node, tail == node
      else:
        # Case 2: head == node, tail != node
   else; 
     if self.tail == node:
        # Case 3: head != node, tail == node
     else:
        # Case 4: head != node, tail != node

Only two comparisons needed.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants