Hi, I am using the sorted () function in Python to order a two-dimensional array (I want to sort the columns in the same way as in a classic spreadsheet).
In the example below, I use itemgetter (0) to sort the grid based on the contents of the first column.
But sorted ones return empty lines before non-empty ones.
>>> import operator >>> res = [['charly','male','london'], ... ['bob','male','paris'], ... ['alice','female','rome'], ... ['','unknown','somewhere']] >>> sorted(res,key=operator.itemgetter(0)) [['', 'unknown', 'somewhere'], ['alice', 'female', 'rome'], ['bob', 'male', 'paris'], ['charly', 'male', 'london']] >>>
while I will need this to return this:
[['alice', 'female', 'rome'], ['bob', 'male', 'paris'], ['charly', 'male', 'london'], ['', 'unknown', 'somewhere']]
Is there an easy way to do this?