removing an instance of an object in python list

Viewed 36791

I Think this should work but its giving me an error. I have a list that contains objects of class node. I have two different lists

  1. open_list
  2. node_list.( they are not the same lengthwise, ordering wise)

When I find a specific node in the open_list I need to delete it from the node_list. I know that the lists have addresses to the objects stored in them

so when i try to do

removed = open_list.pop(min_index) 
node_list.remove(removed) 

it gives me an error saying

node_list.remove(removed)
ValueError: list.remove(x): x not in list

but the list just contains addresses that act like pointers right? it should match up the same addresses. i printed out the address of removed and the whole node_list (only 10 items for now don't fear) print out: (the last item in node_list matches the address of removed:

removed: <__main__.node instance at 0x0124A440>
node_list: [<__main__.node instance at 0x01246E90>, <__main__.node instance at 0x01246EE0>, <__main__.node instance at 0x0124A300>, <__main__.node instance at 0x0124A328>, <__main__.node instance at 0x0124A350>, <__main__.node instance at 0x0124A378>, <__main__.node instance at 0x0124A3A0>, <__main__.node instance at 0x0124A3C8>, <__main__.node instance at 0x0124A3F0>, <__main__.node instance at 0x0124A418>, <__main__.node instance at 0x0124A440>]

Thanks

follow-up Q

so I want to check if the node i want to remove exists in the node_list. when i looked up some simple list functions on http://docs.python.org/tutorial/datastructures.html

list.index(x) and remove.index(x) both give an error if the element is not in the list. this caused my program to stop running. to bypass this, can i use this statement before the .remove(): node in node_list i think the in checks to see if an element is part of a list and returns a bool. just double checking thanks,

3 Answers
Related