Skip to content

Commit a50c696

Browse files
authored
Create Reduce_method.md
1 parent 1edef56 commit a50c696

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

snippets/python/Reduce_method.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Reduce Method
2+
### 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.
3+
4+
_tags_: reduce
5+
6+
# Snippet
7+
```
8+
# following code will reduce a list to give a result based on particular function
9+
10+
from functools import reduce
11+
12+
list_of_numbers = [1, 2, 3, 4, 5]
13+
prod = 1
14+
15+
def multiplication(a, b):
16+
return a*b
17+
18+
result = reduce(multiplication, list_of_numbers)
19+
print(result)
20+
```

0 commit comments

Comments
 (0)