python 对字符串列表按字符串数字大小排序 sorted
a>>> ['7:00', '8:00', '9:20', '10:00', '11:00', '12:00', '12:50', '14:00', '14:50', '16:00', '17:00', '17:50', '21:00', '22:30', '9:00', '10:30', '11:00', '12:30', '14:00', '15:00', '16:00',
·
a
>>> ['7:00', '8:00', '9:20', '10:00', '11:00', '12:00', '12:50', '14:00', '14:50', '16:00', '17:00', '17:50', '21:00', '22:30', '9:00', '10:30', '11:00', '12:30', '14:00', '15:00', '16:00', '17:10', '18:00', '19:00', '21:00', '22:30']
b = sorted(a, key=lambda x: int(x[:-3]+x[-2:]))
b
>>> ['7:00', '8:00', '9:00', '9:20', '10:00', '10:30', '11:00', '11:00', '12:00', '12:30', '12:50', '14:00', '14:00', '14:50', '15:00', '16:00', '16:00', '17:00', '17:10', '17:50', '18:00', '19:00', '21:00', '21:00', '22:30', '22:30']
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献5条内容
所有评论(0)