You shouldn't overwrite the builtin list constructor, list, use another name instead like this:
>>> a_list = [['D', 'F', 'E', 'D', 'F', 'D'],['A', 'F', 'E', 'C', 'F', 'E'],['C', 'E', 'E', 'F', 'E', 'E'],['B', 'F', 'E', 'D', 'F', 'F']]
To sort the list in place, use the list.sort method:
>>> a_list.sort()
>>> a_list
[['A', 'F', 'E', 'C', 'F', 'E'], ['B', 'F', 'E', 'D', 'F', 'F'], ['C', 'E', 'E', 'F', 'E', 'E'], ['D', 'F', 'E', 'D', 'F', 'D']]
The built-in function, sorted, returns a new list, which is something you didn't seem to want to do. It returns a new list, which if you no longer need the old list would waste space in memory.
Python automatically sorts on the first element. It then automatically sorts on the second, third, and so on. Using lambda as others suggested would mean you would only sort on the first element, and the following elements would be ignored.
>>> a_list = [['b', 'f'],['b', 'e'],['b', 'd'],['a', 'c'],['a', 'b'],['a', 'a'],]
>>> a_list.sort(lambda x,y : cmp(x[0], y[0]))
>>> a_list
[['a', 'c'], ['a', 'b'], ['a', 'a'], ['b', 'f'], ['b', 'e'], ['b', 'd']]
This is why the sort is described as a stable sort
>>> help(list.sort)
Help on method_descriptor:
sort(...)
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
cmp(x, y) -> -1, 0, 1
list. stackoverflow.com/questions/21068315/…