We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9f53cab commit d04828fCopy full SHA for d04828f
Misc/Lambda,map,reduce,filter.py
@@ -0,0 +1,27 @@
1
+'''lambda is a one line anonymous function '''
2
+func = lambda x,y: x if x>y else y #function to return max of two numbers
3
+print(func(2,7))
4
+#7
5
+
6
7
+from functools import reduce
8
+lis = [1,2,3,4]
9
+print(reduce(lambda x,y:x+y,lis)) #multiplying all elements of a list using FILTER
10
+#10
11
12
13
+print(list(map(lambda x: x**2, lis))) #squaring all elements of a list using MAP
14
+#[1, 4, 9, 16]
15
16
17
18
+print(list(filter(lambda x: x>10,lis))) #filtering elements of a list using FILTER
19
+#[] - empty list
20
21
22
+'''
23
24
+In filter if you guessed 16 to be answer, you are wrong.
25
+These functions dont modify the input lists but create new ones
26
27
0 commit comments