0
List Functions: Finding the maximum value in a list
I have given a list and tried to find the max value in the list as follows: ========================== In [68]: list=['5','3','6','a','c'] In [69]: max(list) Out[69]: 'c' ========================== Why did I get the output of max(list) as 'c'. What is the logic used here?
3 Antworten
+ 7
It's all about ASCII code:
48 - 57 range is '0 - 9' chars,
97 - 122 range is 'a - z' chars
Which means:
'5' char = 53 in ASCII
'3' char = 51 in ASCII
'6' char = 54 in ASCII
'a' char = 97 in ASCII
'c' char = 99 in ASCII
I hope it's clear enough :)
+ 3
Yeah, it's 51 😄 Fixed 👌
You're welcome 👍
+ 1
Thanks Jakub M.
Its clear now.
It took me some time to understand as I was not familiar with ASCII code
and also you mis-typed '3' char as 50 instead of 51.