Linked Questions

Popular Questions

I know if I had two lists of, say integers, I could simply do list(set(list1) & set(list2)) to get the intersection. However, in my two lists, I have mutable objects, namely Nodes. Node is a class that can be initialized with a value.

Without having to do a double for-loop, is there any way to get the intersection of two lists based on their ids? I'm looking for something similar to list(set(list1) & set(list2)).

Update: By id I am referring to the built-in id() function in Python which returns the address of where the object is stored in memory.

So, I'm asking what is the Intersection of say, [Node1, Node2, Node3] and [Node100, Node2, Node3]. Obviously I can't use the set intersection method above. I need to identify they are the same by accessing memory. If I can't try to identify them based on their value attribute because they may Node1 may have the same value as Node100, but they are not the same objects in memory.

Related Questions