Functools Reduce in Python
Level 3110 keystrokes
This uses reduce to compute the product of all numbers in a list.
Python code
# reduce() lives in the functools module1from functools import reduce2 # The numbers to multiply3nums = [1, 2, 3, 4, 5]# x is the running product, y the next item: (((1*2)*3)*4)*5 = 1204product = reduce(lambda x, y: x * y, nums)# Prints 1205print(product)Output
120
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 6(× 2)× 2=× 2:× 1[× 1]× 1*× 1