Python: Sort list with parallel list

前端 未结 4 1380
渐次进展
渐次进展 2021-02-19 09:42

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.

How can I sort the HTML list based on the

4条回答
  •  我在风中等你
    2021-02-19 10:07

    You can use zip.

    timestamps, elements = zip(*sorted(zip(timestamps, elements)))
    

    The result will be two tuples which you can convert to lists if you prefer.

提交回复
热议问题