4
I have a list of lists of strings. For example a list, in which the internal lists have size n=3:
listEx = [['verde','preto','laraja'], ['rosa','lilás','azul'], ['bordô','cinza','branco'], [preto, roxo, amarelo]]
If I want to sort the list listEx
, defining as criterion the position 0 of the inner lists I do:
lista = sorted(listEx, key = lambda x: x[0])
But what I want is to define a tiebreaker. Therefore, if there are two lists with equal elements at position 0, the tiebreaker criterion should be position 1. If the tie still persists, take position 2 as the tiebreaker criterion. The same goes for the position n
.
The impasse is that n
is variable. That is, depending on the instance of the problem, the internal lists have different cardinalities. However, I guarantee there will be no lists of different sizes.
Maybe there’s something in Python like qsort
of the C language, where I create a function compara_elementos
, can define my criteria in code form.
That? https://answall.com/q/347634/101
– Maniero