Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get maximum number stored in a list

example #1

numbers = ['1086', '1123', '543', '1180', '1222', '1300', '888']
print(max(numbers))

result: 888,
desired result: 1300

example #2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

numbers = ['1086', '1123', '1180', '1222', '1300']
print(max(numbers))

result: 1300,
desired result: 1300

goal

numbers = ['1086', '1123', '543', '1180', '1222', '1300', '888']
print(max(numbers))

result: 1300,
desired result: 1300

all 3 digit and 4 digit combinations should be involved

first 10 results from google index, that offering "enumarate", "max()", "sort()", [-1], [0] also different variations of "for" etc..

got me to write this question.

at most brain dead copy/paste.

thanks!

>Solution :

You list contains string not integers, you make use of map() to convert the string to integers:

numbers = ['1086', '1123', '543', '1180', '1222', '1300', '888']
print(max(map(int, numbers)))
>>> 1300
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading