1
I have a class defined as follows::
class Cromossomo():
def __init__(self, cromossomo, comprimento): #Construtor
self.cromossomo = cromossomo
self.comprimento = comprimento
From it I have a list of the class Chromosome. called final list.
I want to sort that list by length, from the largest to the smallest. I tried using Sort, Sorted, but I couldn’t.
For example:
def ordenar(lista_final):
sorted(lista_final, key=attrgetter('comprimento'), reverse=True)
ordenar(lista_final)
How do I make it work?
This final list is composed of?
– FourZeroFive
chromosome attribute and length ex: lista_final[0]. chromosome = [1,0,0,1] lists_final[0]. length = 25 I want to sort by length
– Gabriel Albuquerque