Python - Find the greatest number in a list of numbers


Is there any easy way or function to determine the greatest number in a python list? I could just code it, as I only have three numbers, however it would make the code a lot less redundant if I could tell the greatest with a built in function or something.

6/27/2017 9:40:06 PM

Accepted Answer

What about max()

highest = max(1, 2, 3)  # or max([1, 2, 3]) for lists
12/4/2017 2:26:39 AM

You can use the inbuilt function max() with multiple arguments:

print max(1, 2, 3)

or a list:

list = [1, 2, 3]
print max(list)

or in fact anything iterable.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow