I am new to Python and don't understand why such a thing does not work. I can not find the problem raised elsewhere.
toto = {'a':1, 'c':2 , 'b':3}
toto.keys().sort()
(toto.keys()).sort()
eval('toto.keys()').sort()
But if I check the type, I see that I am calling sort () on the list, so what is the problem.
toto.keys().__class__ # yields <type 'list'>
The only way I have to work is to add a temporary variable that is ugly
temp = toto.keys()
temp.sort()
What I'm missing here should be the best way to do this.
source
share