#Background#
I have a list of 50 million $A-A_i$ pairs, where $i>1$ and $A$ is some text. I need to extract the $A$ values from the list, so I get a new list of unique $A$ values.:
$$
\text{New List}= \{A, B, C, ...\}
$$
Here is a generic illustration of what the list of pairs looks like:
list of pairs = [['A', 'A1'],
['A', 'A2'],
['A', 'A3'],
['B', 'B1'],
['C', 'C1'],
...
Here is some actual data:
`['394.NGR_c13430',
'(3R)-hydroxymyristoyl-[acyl-carrier-protein] dehydratase'],`
`['394.NGR_c31790',
'(Di)nucleoside polyphosphate hydrolase'],`
`['394.NGR_c00410',
'(Dimethylallyl)adenosine tRNA methylthiotransferase MiaB'],`
`['394.NGR_c28950',
'1,4-alpha-D-glucan:1,4-alpha-D-glucan 6-glucosyl-transferase'],`
`['394.NGR_c28950',
'1,4-alpha-glucan branching enzyme GlgB'],`
`['394.NGR_c34010', '1-(5-phosphoribosyl)-5-[(5-ph']]`
` 9606.ENSP00000170630 1IAR`
` 9606.ENSP00000170630 1ITE`
` 9606.ENSP00000170630 287261`
` 9606.ENSP00000170630 287263`
` 9606.ENSP00000170630 287265`
` 9606.ENSP00000170630 287267`
` 9606.ENSP00000170630 287269`
` 9606.ENSP00000170630 287271`
` 9606.ENSP00000170630 3566`
(Sorry for the sloppy formatting, but I hope you get the idea.)
#My Attempt#
I'm doing:
names := empty list
for row in list:
____name := first element in row
____if name not in names:
________append name to names
However, this approach is extremely slow. Even running this on only 10 thousand of the pairs takes more than half an hour. I'm only a statistician and not familiar with the intricacies of computer science or Python. Is there a better way of doing this?
Also...#
I know for a fact that there are only 10 million unique values.
With $n$ = 50 million and $p$ = 10 million, I thought my algorithm was $O(np)$. Is it? Is this efficient?
Thank you