Skip to content

Commit b9fe426

Browse files
authored
Merge pull request bradtraversy#9 from saksham715/patch-1
made a new file Create map, filter and reduce.py
2 parents bdcbebc + 7096baf commit b9fe426

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from setuptools import reduce #importing reduce module for using reduce function
3+
4+
l1 = [2,3,4,5,6]
5+
6+
mapping_the_l1 = list(map(lambda x: x*2, l1)) # MAP FUNCTION APPLIES THE GIVEN COMMAND TO EVERY INDEX OF A LIST
7+
# IN THIS CASE WE ARE MULTIPLYING EVERY CHARACTER IF LIST l1 TO 2 USING LAMBDA FUNCTION
8+
9+
print(mapping_the_l1)
10+
11+
12+
filtering_the_l1 = list(filter(lambda x: x%2 ==0)) #FILTER FUNCTION FILTERS THE LIST ACCORDING TO OUR WISH
13+
# IN THIS CASE WE ARE FILERING THE NUMBER WHICH IS DIVISIBLE BY 2 IN l1.
14+
15+
print(filtering_the_l1)
16+
17+
def add(x, y):
18+
return x+y
19+
20+
reducing_the_l1 = reduce(add, l1) # REDUCE FUNCTION IS USED FOR DOING MATHEMATICAL OPERATIONS IN A LIST
21+
# HERE, WE ARE ADDING ALL THE CHARACTERS THE LIST l1
22+
23+
print(reducing_the_l1)

0 commit comments

Comments
 (0)