I have a python list of time values that I extracted from a web log. I have the list in the format of %H:%M:%S
. How would I sort the time values in ascending o
import time
sorted((time.strptime(d, "%H:%M:%S") for d in time_list), reverse=True)
sorted([tuple(map(int, d.split(":"))) for d in my_time_list])
Where each element in my_time_list is of the form you describe, for example:
>>> my_time_list
["03:12:08", "14:10:01"]
you should be able use the method sort(key=str.lower)
since your time is parsed as a string
Just sorted(time_list)
works fine.
>>> sorted(["14:10:01", "03:12:08"])
["03:12:08", "14:10:01"]