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
Enumerate will give you a list of (index,item) tuples for each item in the list. You can sort this using the index to read the sort key from the timestamps list. Then peel off the html elements:
sorted_elems = [elem for i,elem in sorted(enumerate(html_elements),
key=lambda x:timestamps[x[0]])]
What could be simpler?