I am looking for the most efficient way to update a list.
I have a variable self.myGlobalList = []
I also have a recursive function that on each one of its calls is going to generate a new list with coordinates.
Say in the first iteration, I obtain the following list:
[(1,1), (21,22), (84,6)]
Since self.myGlobalList
does not contain any of those coordinates, I will append them to it:
for elem in generatedList:
if elem not in self.myGlobalList:
self.myGlobalList.append(elem);
Then, on the second iteration I obtain a new generated list:
[(1,1), (21,22), (9,18), (71, 89), (13, 21)]
Now my code will again go through each element of the newly generated list and check if any are missing from self.myGlobalList
, and if yes, append them. The result should contain the new elements:
[(1,1), (21,22), (84,6), (9,18), (71, 89), (13, 21)]
So far so good, everything works fine.
However, my lists can contain more than 500 000+ coordinates. In terms of efficiency, will this method be sufficient, and are there any suggestions you could offer in order to optimise it?