This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Max() Not Working Properly
Type: Stage:
Components: IDLE Versions: Python 3.1
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, lovelygoo2
Priority: normal Keywords:

Created on 2009-09-21 03:03 by lovelygoo2, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg92920 - (view) Author: (lovelygoo2) Date: 2009-09-21 03:03
>>> max(['34', '7'])
'7'
>>> #This happens because it is comparing strings.
>>> #I have found a way to fix it though.
>>> def Max(li):
...    greatest=li[0]
...    for item in li:
...        for item2 in li:
...            if int(item)<int(item2) or int(item)<greatest:
...                break
...            else:
...                greatest=int(item)
...    return(greatest)
msg92921 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-09-21 03:14
This is the way strings are compared. You can change this easily,
though, using max(list_of_string_numbers, key=int).
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51204
2009-09-21 03:14:58benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg92921

resolution: wont fix
2009-09-21 03:03:04lovelygoo2create