Zeno Zeno - 1 month ago 10
Python Question

Python: Sort list with parallel list

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 time/date list? The time/date is in a timestamp format.

Answer Source

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.