您的位置:首页技术文章
文章详情页

python - 老铁们,在列表中如何对时间进行排序~

【字号: 日期:2022-07-28 17:56:39浏览:40作者:猪猪

问题描述

fx = [{’次数’: 2, ’时间’: ’10:45:00’}, {’次数’: 4, ’时间’: ’14:58:00’}, {’次数’: 5, ’时间’: ’09:59:00’}, {’次数’: 28, ’时间’: ’08:13:00’}, {’次数’: 34, ’时间’: ’08:28:00’}, {’次数’: 4, ’时间’: ’05:12:00’}, {’次数’: 12, ’时间’: ’04:56:00’}]

上面的这个列表中,进行时间上的排列,比如最后那个是4点56的,排在第一位,9点59的那个排在最后面。

老铁们,帮帮忙啊~~谢谢

问题解答

回答1:

fx.sort(key=lambda item: int(item[’时间’][:2])*60 + int(item[’时间’][3:5]))回答2:

取出来时间,desc

回答3:

fx.sort(function (pre, next) {return new Date(’1970/01/01 ’ + pre[’时间’]) - new Date(’1970/01/01 ’ + next[’时间’]) }); console.log(JSON.stringify(fx))

标签: Python 编程