+ 1

The max function ( Python )

What would happen if you tried to use this function in a list that only contained strings?

14th Dec 2018, 11:48 PM
Monya 🇮🇶
Monya 🇮🇶 - avatar
2 ответов
+ 4
If you compare two strings, the first letters are compared for their unicode position. If they are equal, then the second letters are compared too, until one letter is 'bigger'. Now logically, if you apply this to max, the string with the highest value determined by the above routine would be the result.
15th Dec 2018, 12:17 AM
HonFu
HonFu - avatar
+ 4
From the docs: https://docs.python.org/3/tutorial/datastructures.html#comparing-sequences-and-other-types Python strings are compared lexically.
15th Dec 2018, 1:03 AM
Hatsy Rei
Hatsy Rei - avatar