Python:具有并行列表的排序列表 [英] Python: Sort list with parallel list
本文介绍了Python:具有并行列表的排序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用HTML元素填充的列表.我还有一个填充日期/时间的列表,它与HTML列表平行.
I have a list that is filled with HTML elements. I also have a list filled with date/times, which is parallel to the HTML list.
如何根据时间/日期列表对HTML列表进行排序?时间/日期采用时间戳格式.
How can I sort the HTML list based on the time/date list? The time/date is in a timestamp format.
推荐答案
您可以使用> c0> .
timestamps, elements = zip(*sorted(zip(timestamps, elements)))
结果将是两个元组,您可以根据需要将其转换为列表.
The result will be two tuples which you can convert to lists if you prefer.
这篇关于Python:具有并行列表的排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文