Skip to content

Commit 41a262c

Browse files
committed
python
1 parent e4500f4 commit 41a262c

5 files changed

+75
-0
lines changed

day32(seek tell).py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
print(f.tell()) # ye current postion return kr dega
1010
data =f.read(5) # wha se next 5 character read karega
1111
print(data)
12+
13+
1214

1315

1416

day33(Lambdafun).py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# def double(x):
2+
# return x*2
3+
double=lambda x:x*2
4+
print(double(5))
5+
6+
# def cube(x):
7+
# return x*x*x
8+
cube=lambda x:x*x*x
9+
print(cube(4))
10+
11+
avg=lambda x,y:(x+y)/2
12+
print(avg(4,5))
13+
14+
def appl(fx,value):
15+
return 6 +fx(value)
16+
print(appl(cube,2))

day34(Map filter ).py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#MAP higher order function
3+
# def cube(x):
4+
# return x*x*x
5+
# print(cube(2))
6+
7+
l=[1,2,3,4,5]
8+
newl=[]
9+
# for item in l:
10+
# newl.append(cube(item))
11+
# newl=list(map(cube,l)) # this is why map is used
12+
newl=list(map(lambda x:x*x*x,l)) # this is why map is used
13+
print(newl)
14+
15+
#FILTER higher order function
16+
17+
def filter_fun(a):
18+
return a>2
19+
newnewl= list(filter(filter_fun,l))
20+
print(newnewl)
21+
22+
23+
24+
25+
26+
27+
9

day35(reduce).py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from functools import reduce
2+
3+
# List of numbers
4+
numbers = [1, 2, 3, 4, 5]
5+
6+
# Calculate the sum of the numbers using the reduce function
7+
8+
# def mysum(x,y):
9+
# return x+y
10+
# sum=reduce(mysum,numbers)
11+
sum = reduce(lambda x, y: x + y, numbers)
12+
# Print the sum
13+
print(sum)

day36(is,==).py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
a = None
2+
b = None
3+
4+
print(a is b) # exact location of object in memory
5+
print(a is None) # exact location of object in memory
6+
print(a == b) # value
7+
8+
a = [1,3,4]
9+
b = [1,3,4]
10+
print(a is b) #ye uska exact location deta h memory me
11+
print(a == b) #ye value ko check krta h
12+
13+
14+
a=(1,2,3)
15+
b=(1,2,3)
16+
print(a is b) # ye dono true diye kiuki tuple h immutable h isiliye dono true return karegnge
17+
print(a ==b)

0 commit comments

Comments
 (0)