I have a list of 10.000 elements of custom objects. The important thing is that these objects have a graph as an attribute (consisting of something between 20 and 500 nodes).
Now I would like to remove all the duplicates in the list, where I assume two objects to be equal if and only if their graphs are isomorphic.
My code looks something like that:
import networkx as nx
#
def remove_duplicates(list_):
filtered_list = list()
while len(list_) > 0:
A = list_.pop()
filtered_list.append(A)
for B in list_:
if A.num_of_nodes == B.num_of_nodes:
if nx.is_isomorphic(A.graph, B.graph, node_match=node_check):
list_.remove(B)
return filtered_list
However, the program stops progressing at a certain point. I checked the activity monitor and apparently the memory is not an issue, but maybe the CPU.
Does someone have a hint on how to solve this a little bit more efficiently/elegantly? For smaller samples, my code worked well.