Some python code that keeps throwing up an invalid syntax error:
stat.sort(lambda x1, y1: 1 if x1.created_at < y1.created_at else -1)
Some python code that keeps throwing up an invalid syntax error:
stat.sort(lambda x1, y1: 1 if x1.created_at < y1.created_at else -1)
Try the and-or trick:
lambda x1, y1: x1.created_at < y1.created_at and 1 or -1
This is a better solution:
stat.sort(key=lambda x: x.created_at, reverse=True)
Or, to avoid the lambda altogether:
from operator import attrgetter
stat.sort(key=attrgetter('created_at'), reverse=True)