Getting caught up in a solution to NoneType errors stemming from using my functions add and append in the below code to an empty Double_list class object. Best way to avoid?
class Dbl_Node:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
class Double_list:
def __init__(self): # Creates initial list w/ head and tail as None
self.head = None
self.tail = None
def add(self, item): # adds node to beginning/head of list
temp = self.head
self.head = Dbl_Node(item)
temp.prev = self.head
self.head.next = temp
def append(self, item): # adds node to end/tail of list
temp = self.tail
self.tail = Dbl_Node(item)
self.tail.prev = temp
temp.next = self.tail
'in add temp.prev = self.head builtins.AttributeError: 'NoneType' object has no attribute 'prev'It is referring to the line with temp.prev = self.headeditbutton under the question tags. This is the preferred method to add information to a question as things sometimes get lost in the comment threads.