array max

Go Back home

Iterative

1 A = [0,1,0,2,1,0,1,3,2,1,2,1]
2 m = 0
3 for a in A:
4 m = max(a, m)
5 print(m)

Output:

1 3

Functional

1 from functools import reduce
2 A = [0,1,0,2,1,0,1,3,2,1,2,1]
3 m = reduce(lambda a, x: max(a, x), A)
4 print(m)

Output:

1 3

See Also

array min