0
Can anyone explain how this is sorted like this
2 Respostas
+ 5
It is comparing each character in a string by its ascii value , strings are compared character by character ,so first of each one is checked and so P is smaller than f and i ,and f is smaller than i and we get a sorted list in ascending order ,
+ 2
You can change the sort criteria by passing a function or lambda as the key argument to the sort() method.
For instance this will sort the list by the length of the str elements.
words.sort(key=lambda x: len(x))