I have a list of lines read from a file. I need to sort the list by time stamp. I have parsed out the time stamp using regular expressions and place them into a separate list. T
I think you could do
[line for (time,line) in sorted(zip(listofTimes, listofLines))]
But if you have (or could write) a function to automatically extract the time from the line,
def extract_time(line):
...
return time
you could also do
listofLines.sort(key=extract_time)
or if you want to keep the original list intact,
sorted(listofLines, key=extract_time)