I have the following code:
def popLast(aLinkedList):
ptr = aLinkedList
while ptr != None:
if ptr['next']['next'] == None and ptr['next'] != None:
del_node = ptr['data']
ptr['next'] = ptr['next']['next']
ptr = ptr['next']
return (del_node,ptr)
When I put
myLinkedList = createList(['a', 'b', 0, [1, 2]])
for i in range(getLength(myLinkedList)):
(a, myLinkedList) = popLast(myLinkedList)
print(a, end = ", new list: ")
printList(myLinkedList)
It keeps giving me
UnboundLocalError: local variable 'del_node' referenced before assignment
When I just use popLast(myLinkedList), there is no problem. Everything works fine. I don't know whether it is because my returning tuple is the problem.
createlistis not explained in your code. Please give us a Minimal, Complete, and Verifiable example.while ptr is not Noneinstead ofwhile ptr != None.