I am learning about " list"
Please consider the following example:
j=['1', '12', 'KOO', 'LOO']
If we do :
>>> max (j)
How is max being determined above? I know it is a dumb example but I am just curious what Python thinks it is larger value in the list .
Welcome to the Github Community Forum.
It's a little tricky to understand it but the reason is because order in a list of string is given by the lexicographical order, if you open a dictionary you will understand this concept very well. For example take this list of string:
j = ['1', '11', '234', 'a']
the max element of this is a and the minimum element is 1, this because 1<a and 234<a.
You can try add some more element and change the order to this list:
j = ['a', 'bz', 'z', 'zzzz', '$', '11', '234']
Here the minimum element is $ and the maximum is zzzz.
You can see the exact order using the sort method:
j = ['a', 'bz', 'z', 'zzzz', '$', '11', '234'] print(sort(j))
the output will be:
['$', '11', '234', 'a', 'bz', 'z', 'zzzz']
To be precise i give some more example:
bed > animal zap > bed animal > 123456789 123456789 > $
WOO > LOO
LOO > KOO KOO > 12
LOO > 1
Think about words in dictionary.
Hope this help :)
Mark helpfull posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great contents!
Good explanation. Minor typo in the last example I think:
LOO > WOO
LOO < WOO
Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!