Open this example in the interactive library
Source code
values = [3, 1, 5, 2, 8]
from itertools import accumulate
print(list(accumulate(values, max)))Sample output
[3, 3, 5, 5, 8]

Calculate a running maximum. A self-contained example using the Python standard library.
Open this example in the interactive library
values = [3, 1, 5, 2, 8]
from itertools import accumulate
print(list(accumulate(values, max)))[3, 3, 5, 5, 8]