a = ['aa', 'd', 'c','a']
a.sort(key = lambda x:len(x))
['d', 'c', 'a', 'aa']
sorted("This is a test string from Andrew".split(), key=str.lower)
['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
In [1]: x = ['a', 'aaa', 'A', 'AA', 'AAA', 'AaA']
In [2]: sorted(x)
Out[2]: ['A', 'AA', 'AAA', 'AaA', 'a', 'aaa']
In [3]: [[ord(i) for i in el] for el in sorted(x)]
Out[3]: [[65], [65, 65], [65, 65, 65], [65, 97, 65], [97], [97, 97, 97]]