Sort two lists based on one Python

ask question on maxinterview

you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content

please be clear, to the point and respectful

Submit

To sort two lists in parallel, what's the way of sorting by one list first, then for elements with the same value, sorting by the second list? Either list could have duplicated elements.

list_a = [3,2,4,4,5] list_b = ['d','b','a','c','b']

The output needs to be based on [1] the value from list_a from the largest to the smallest, and [2] for elements with the same value in list_a, sort by alphabetical order in list_b.

list_a = [5,4,4,3,2] list_b = ['b','a','c','d','b']

Any ideas?

Video liên quan

Chủ Đề