diff --git a/snippets/python/Reduce_method.md b/snippets/python/Reduce_method.md new file mode 100644 index 0000000..d0d5180 --- /dev/null +++ b/snippets/python/Reduce_method.md @@ -0,0 +1,20 @@ +# Reduce Method +### The reduce() function is used to apply a particular function passed in its argument to all of the list elements mentioned in the sequence passed along. + +_tags_: reduce + +# Snippet +``` +# following code will reduce a list to give a result based on particular function + +from functools import reduce + +list_of_numbers = [1, 2, 3, 4, 5] +prod = 1 + +def multiplication(a, b): + return a*b + +result = reduce(multiplication, list_of_numbers) +print(result) +```