How can I sort this list in descending order?
timestamp = [ \"2010-04-20 10:07:30\", \"2010-04-20 10:07:38\", \"2010-04-20 10:07:52\", \"2010
In one line, using a lambda:
lambda
timestamp.sort(key=lambda x: time.strptime(x, '%Y-%m-%d %H:%M:%S')[0:6], reverse=True)
Passing a function to list.sort:
list.sort
def foo(x): return time.strptime(x, '%Y-%m-%d %H:%M:%S')[0:6] timestamp.sort(key=foo, reverse=True)