[[+content_image]]
A
A
aqau1232021-11-22 13:48:06
Python
aqau123, 2021-11-22 13:48:06

How to sort an array of arrays by a certain element?

There is an array:


How to sort it so that in the end it will be in the form:
[[1, '...', '...'], [2, '...', '...'], [3, '...', '...'], [4, '...', '...']]

There is already a solution, but I'm sure it's not the most optimal, and the script usually works with large data, so the difference will be noticeable.
My head doesn’t boil at all now, I was looking for a bug for an hour and a half, as it turned out, set () changes the order of elements ...

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
antares4045, 2021-11-22
@aqau123

Look at the key parameter of the sort and sorted builtin functions. They are made primarily to solve your problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question