I have a very big 2D array where the second elements are not unique. Something like this:
list = [ ['text43','value43'],
['text23','value23'],
['text12','value12'],
['text43','different_val_43'],
['text12','another_value12'],
['text04','value04'],
['text43','anohter_value43'] ]
I would like to sort it by the first element but not in alphabetical order, just in the order of appearance of first element. Desired output:
list = [ ['text43','value43'],
['text43','different_val_43'],
['text43','anohter_value43'],
['text23','value23'],
['text12','value12'],
['text12','another_value12'],
['text04','value04'] ]
sorted(list1, key=lambda x: -int(x[0][-2:]))?listas the variable name of a python list. @BearBrown 's answer looks right.list.