Sort Python Columns with corresponding rows

Viewed 192

I want to sort column values depending on a row full of int:

cart = [[1, 3, 0, 2], ['olives', 'tomatoes', 'avocado', 'patato']]

and have this

new_cart= [[0, 1, 2, 3], ['avocado', 'olives', 'patato', 'tomatoes' ]]

In other words I want strings to sorted by the integers values which they corresponds:

I found these questions but non of them does what I want:

how to sort 2d array by row in python?

How to sort multidimensional array by column?

2 Answers
Related