Python: Sort list with parallel list

前端 未结 4 1388
渐次进展
渐次进展 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:19

    Zip the two lists up into tuples, sort, then take the HTML back out of the tuple:

    zipped = zip(timestamps, htmls)
    zipped.sort()
    sorted_htmls = [html for (timestamp, html) in zipped]
    

提交回复
热议问题