Let's assume I have a list, structured like this with approx 1 million elements:
a = [["a","a"],["b","a"],["c","a"],["d","a"],["a","a"],["a","a"]]
What is the fastest way to remove all elements from a
that have the same value at index 0?
The result should be
b = [["a","a"],["b","a"],["c","a"],["d","a"]]
Is there a faster way than this:
processed = []
no_duplicates = []
for elem in a:
if elem[0] not in processed:
no_duplicates.append(elem)
processed.append(elem[0])
This works but the appending operations take ages.