Last active
September 24, 2020 14:00
-
-
Save Kush1101/07db8c8627142fecd6d82362eecc88d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import accumulate | |
from operator import mul | |
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
print(list(accumulate(iterable))) | |
# Prints the addition after each iteration | |
# OUTPUT | |
""" | |
[1, 3, 6, 10, 15, 21, 28, 36, 45, 55] | |
""" | |
print(list(accumulate(iterable, mul))) | |
# Prints the mutiplication after each iteration (= factorial of the number) | |
""" | |
[1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment