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?

31st Mar 2017, 10:52 AM
deepak deo
deepak deo - avatar
3 Réponses
+ 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 :)
31st Mar 2017, 11:02 AM
Jakub M.
Jakub M. - avatar
+ 3
Yeah, it's 51 😄 Fixed 👌 You're welcome 👍
31st Mar 2017, 11:25 AM
Jakub M.
Jakub M. - avatar
+ 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.
31st Mar 2017, 11:23 AM
deepak deo
deepak deo - avatar