Skip to content

Instantly share code, notes, and snippets.

@Kush1101
Created September 24, 2020 14:10
Show Gist options
  • Save Kush1101/6c88c97d069f9e7a4b7d7a251344a6a7 to your computer and use it in GitHub Desktop.
Save Kush1101/6c88c97d069f9e7a4b7d7a251344a6a7 to your computer and use it in GitHub Desktop.
from itertools import accumulate
data = [-1, 2, 5, 7, -20, 9, 12, 9, 16, 4]
print(list(accumulate(data, min)))
#Prints the running minimum of the data
#OUTPUT
'''
[-1, -1, -1, -1, -20, -20, -20, -20, -20, -20]
'''
print(list(accumulate(data, max)))
#Prints the running maximum of the data
#OUTPUT
'''
[-1, 2, 5, 7, 7, 9, 12, 12, 16, 16]
'''
my_func = lambda a,b: (a + b) * 2
print(list(accumulate(data, my_func)))
#Prints the output calculated by the my_func
#OUTPUT
'''
[-1, 2, 14, 42, 44, 106, 236, 490, 1012, 2032]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment