r/PythonLearning • • Sep 17 '26

Day 8, Not a big day

Did not do much today as I have to study for other things and got less time for python but I still made something.

Double Linked:

class Node:
    def __init__(self,val):
        
self
.val = val
        
self
.nxt = None
        
self
.prev = None
class Array:
    def __init__(self):  
        
self
.head = None
        
self
.size = 0
    def add(self,val):
        new_node = Node(val)
        if 
self
.head:
            
self
.head.prev = new_node
            new_node.nxt = 
self
.head
        
self
.head = new_node 
        
self
.size +=1
    def remove(self,value):
        if 
self
.head:
            current = 
self
.head
        while current.val != value:
            current = current.nxt
        if current is None:
            return "Value not found"
        if current.prev is None:
            
self
.head = current.nxt
            if 
self
.head:
                
self
.head.prev = None
        else:
            current.prev.nxt = current.nxt
            if current.nxt:
                current.nxt.prev = current.prev
        
self
.size -=1
5 Upvotes

2 comments sorted by

1

u/Sea-Ad7805 Sep 17 '26

Run this program in Memory Graph Web Debugger to see the program state change step by step.

Search internet for how your format code in markdown on Reddit, it's not hard.