Method of sorted in python -


the same code, run several times, different results. why following results not sorted?

enter image description here enter image description here

you put results dict – data structure not guarantee order of keys/values. seems you're aware of that, judging call sorted().

however, function doesn't work presume: rather modifying list (or iterable, in general), returns new one. documentation linked above states:

return new sorted list items in iterable.

and since result of function isn't assigned variable, perishes. alternately, result can used directly collection iterate on in for loop, this:

for key in sorted(scores):     print(scores[key] + ' had ' + key) 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -