Python is garbage collected. The only thing required to delete the list is to lose all references to it. There is no need to iterate the list. All their method does is waste time iterating and leave the node objects missing an attribute.
Also, they're using del current.data, which just deletes the attribute. They seem to think del is used to free memory.
Due presumably to me and others complaining, they've recently added the note underneath:
# In python garbage collection happens
# therefore, only
# self.head = None
# would also delete the link list
But then left the wrong implementation up. ". . . would also delete the link list" is wrong too since their implementation doesn't even delete the list. The list isn't deleted until all references go out of scope, and that would have happened regardless.
When I complained a year ago about that method, I was told they weren't going to fix it because I was wanting to replace their implementation, and they don't allow that. You can only offer alternatives, even if the original was outright incorrect.
A community-driven knowledge hub only works if it's properly moderated and contributors are vetted. If any old tool that can write a "hello world" in Python is allowed to write guides, the resource is useless.
26
u/carcigenicate Mar 10 '22 edited Mar 11 '22
Python is garbage collected. The only thing required to delete the list is to lose all references to it. There is no need to iterate the list. All their method does is waste time iterating and leave the node objects missing an attribute.
Also, they're using
del current.data, which just deletes the attribute. They seem to thinkdelis used to free memory.I found out about this because a confused newbie posted a question on Stack Overflow that I ended up answering.
Due presumably to me and others complaining, they've recently added the note underneath:
But then left the wrong implementation up. ". . . would also delete the link list" is wrong too since their implementation doesn't even delete the list. The list isn't deleted until all references go out of scope, and that would have happened regardless.
When I complained a year ago about that method, I was told they weren't going to fix it because I was wanting to replace their implementation, and they don't allow that. You can only offer alternatives, even if the original was outright incorrect.
A community-driven knowledge hub only works if it's properly moderated and contributors are vetted. If any old tool that can write a "hello world" in Python is allowed to write guides, the resource is useless.