I have a list:
[[\'18411971\', \'kinase_2\', 36], [\'75910712\', \'unnamed...\', 160], ...
How about:
inputlist = [['18411971', 'kinase_2', 36], ['75910712', 'unnamed...', 160], ... # obviously not valid syntax
auxinput = aux = ['75910712', '18411971', ...] # ditto
keyed = { sublist[0]:sublist for sublist in inputlist }
result = [keyed[item] for item in auxinput]
There is no need to use sorting here. For large lists this would be faster, because it's O(n)
rather than O(n * log n)
.
In case the keys aren't unique, it is possible to use some variant of an ordered dict (e.g. defaultdict(list)
as per Niklas B's suggestion) to build the keyed representation.