Does anyone know how to sort rows to ["D9", "D10", "E9P", "E10P"] ? I want to sort by the preceding alphabet first and then sort by number inside.
In [2]: rows
Out[2]: ['D10', 'D9', 'E9P', 'E10P']
In [3]: sorted(rows)
Out[3]: ['D10', 'D9', 'E10P', 'E9P']
1. I can sort 9 ahead of 10 like this.
In [9]: sorted(rows, key=lambda row: int(re.search('(\d+)', row, re.IGNORECASE).group(1)))
Out[9]: ['D9', 'E9P', 'D10', 'E10P']
2. This doesn't work for me
In [10]: sorted(rows, key=lambda row: (row, int(re.search('(\d+)', row, re.IGNORECASE).group(1))))
Out[10]: ['D10', 'D9', 'E10P', 'E9P']