From a50c696706594f70e29f62b23d1b830f6c463b52 Mon Sep 17 00:00:00 2001 From: Aakash Dinkar <35952953+aakashdinkar@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:10:42 +0100 Subject: [PATCH] Create Reduce_method.md --- snippets/python/Reduce_method.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 snippets/python/Reduce_method.md 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) +```