Skip to content

Commit f027ab4

Browse files
committed
20-Map, Filter & Reduce
1 parent 3178c0e commit f027ab4

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# arr = [1,4,2,6,12,10]
2+
# result = list(filter(lambda n : n > 4, arr))
3+
# print(result)
4+
nums = [i for i in range(1,11)]
5+
even = list(filter(lambda n: n%2==0, nums))
6+
print(even)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# def cube(n):
2+
# return n*n*n
3+
# print(cube(3))
4+
5+
arr = [1,4,2,6,12,10]
6+
# newList = []
7+
# for i in arr:
8+
# newList.append(cube(i))
9+
# print(newList)
10+
new = list(map(lambda x: x*x*x,arr))
11+
print(new)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from functools import reduce
2+
# nums = [55]
3+
nums = [i for i in range(1,11)]
4+
# print(nums)
5+
6+
sum = reduce(lambda x,y: x+y, nums)
7+
print(sum)

0 commit comments

Comments
 (0)