for elem in cur.fetchall():
if elem[0] in publist:
publist[elem[0]]["cat_id"].add(elem[5])
else:
publist[elem[0]]={"title": elem[1],
"text": elem[2],
"date": elem[3],
"author": elem[4],
"cat_id": {elem[5]
}}
pub_sorted=sorted(publist,
key=lambda elem:datetime.strptime(elem["date"], "%d.%m.%Y %H:%M:%S"),
reverse=True)
TypeError: 'int' object is not subscriptable
worklist=[{"work_id": elem[0],
"title": elem[1],
"date": elem[2],
"customer": elem[3],
"author": elem[4],
"workfrom": elem[5],
"workto": elem[6]
} for elem in cur.fetchall()]
work_sorted=sorted(worklist(),
key=lambda work:datetime.strptime(work["workfrom"], "%d.%m.%Y"),
reverse=True)
pub_sorted=sorted(publist.items(),
key=lambda elem: datetime.strptime(elem[1]["date"], "%d.%m.%Y %H:%M:%S"),
reverse=True)
И судя по данным реально сортирует, но данные в итоге не в виде словаря, [(key, dict-value), (key, dict-value)
(key, dict-value)]