Delete_node function

In the delete_node function appended, is it necessary to set cur_node = None at the end? As I can assume, when assigning objects with the = operator it is assigned by reference not by value and putting None in cur_node ensures that no variable references the previously contained object right? So it is memory efficient
def delete_node(self, key):

cur_node = self.head

if cur_node and == key:

self.head =

cur_node = None


Hey @Carlos_Cortes_Vazque!
When we assign None, the reference count decreases, and the python interpreter uses reference counting for memory management. If the reference count is 0 (after setting the curr_node to None), the garbage collector will eventually clean and free up space for us. So the memory is deallocated.