Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort a list of time values?

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 order?

like image 282
intuition Avatar asked Jul 18 '13 03:07

intuition


People also ask

How do you sort dates in a list?

Drag down the column to select the dates you want to sort. Click Home tab > arrow under Sort & Filter, and then click Sort Oldest to Newest, or Sort Newest to Oldest.

How do you sort elements in a list?

sort() method sorts the elements of a list in ascending or descending order using the default < comparisons operator between items. Use the key parameter to pass the function name to be used for comparison instead of the default < operator. Set the reverse parameter to True, to get the list in descending order.

How do I sort a list of dictionaries by value?

To correctly sort a dictionary by value with the sorted() method, you will have to do the following: pass the dictionary to the sorted() method as the first value. use the items() method on the dictionary to retrieve its keys and values. write a lambda function to get the values retrieved with the item() method.


1 Answers

Just sorted(time_list) works fine.

>>> sorted(["14:10:01", "03:12:08"])
["03:12:08", "14:10:01"]
like image 186
hago Avatar answered Sep 23 '22 12:09

hago