Better to use built-in function max
in module builtins:
>>> data = [73284, 8784.3, 9480938.2, 984958.3, 24131, 45789, 734987, 23545.3, 894859.2, 842758.3]
>>> max(data)
9480938.2
Info Page:
max(iterable, *[, default=obj, key=func]) -> value max(arg1, arg2, *args, *[, key=func]) -> value With a single iterable argument, return its biggest item. The default keyword-only argument specifies an object to return if the provided iterable is empty. With two or more arguments, return the largest argument.
Just for the sake of for loop, but its not desirable..
>>> max_value = 0
>>> data = [73284, 8784.3, 9480938.2, 984958.3, 24131, 45789, 734987, 23545.3, 894859.2, 842758.3]
Foor loop to achieve it by setting the max_value
to zero and then evaluate, you need to use float
as your list has floating values not an integers.
#!python/v3.6.1/bin/python3
max_value = 0
data = [73284, 8784.3, 9480938.2, 984958.3, 24131, 45789, 734987, 23545.3, 894859.2, 842758.3]
for mx in data:
if float(mx) > max_value: max_value = float(mx)
print("Highest Value From the List : " , (max_value))
Result:
$ ./max_val.py
Highest Value From the List : 9480938.2
solved Find the max in a list of numbers using the for/while loop