I have a list of lines read from a file. I need to sort the list by timestamp. I checked the timestamp using regular expressions and put them on a separate list. The indices of the two lists will match. As soon as I sort the list of timestamps, I can get the index order.
Is there a way to apply the same index order to the original row list? The result should be a sorted list of source strings.
Example:
listofLines = ['log opened 16-Feb-2010 06:37:56 UTC',
'06:37:58 Custom parameters are in use',
'log closed 16-Feb-2010 05:26:47 UTC']
listofTimes = ['06:37:56', '06:37:58', '05:26:47']
sortedIndex = [2,0,1]
source
share