Professional Documents
Culture Documents
Walchand Institute of Technology, Solapur Information Technology 2021-22 SEMESTER - I
Walchand Institute of Technology, Solapur Information Technology 2021-22 SEMESTER - I
Walchand Institute of Technology, Solapur Information Technology 2021-22 SEMESTER - I
SOLAPUR
INFORMATION TECHNOLOGY
2021-22 SEMESTER –I
Name-Kiran Chavan
Roll No-62
Python Assignment-5
remdup([3,1,3,5]) : [3,1,5]
remdup([7,3,-1,-5]) : [7,3,-1,-5]
remdup([3,5,7,5,3,7,10]) : [3,5,7,10]
Code :
def remdup(l):
l1 = []
for item in l :
l1.append(item)
else:
continue
return l1
op1 = remdup([3,1,3,5])
op2 = remdup([7,3,-1,-5])
op3 = remdup([3,5,7,5,3,7,10])
Output:
2) A two dimensional matrix can be represented in Python row-wise, as a list of
lists: each
inner list represents one row of the matrix. For instance, the matrix
1234
5678
The transpose of a matrix converts each row into a column. The transpose of
the matrix
above is:
Code :
l1 = [ ]
def transpose(m):
for i in range(len(m[0])):
l2 = [ ]
for j in range(len(m)):
l2.append(m[j][i])
l1.append(l2)
return l1
op = transpose([[1,4,9]])
Output:
3)Write a higher order function, sum_all() to calculate the sum of elements in a
list.
sum_all() – It accepts a list and calculates the sum of the elements in the list
based on the
Only those values satisfying the condition should be included in the sum.
Input : [25,26,27,28,29,30,147,187]
Output : 499
30
165
Code :
def sum_all(l,lambda_expr):
print(sum(list(filter(lambda_expr,l))))
l = [25,26,27,28,29,30,147,187]
sum_all(l,lambda x : x>10)
sum_all(l,lambda x : x%10==0 and x<=100)
sum_all(l,lambda x : x>=25 and x<=50)
Output :
The function even() returns a list of all the even numbers from sample_data
The function odd() returns a list of all the odd numbers from sample_data
Create a function sum_of_numbers() which will accept the sample data and/or
a
function.
If a function is not passed, the sum_of_numbers() should return the sum of all
the
Code :
def even(l):
def odd(l):
sample_data = range(1,n)
if fun_name == even:
return sum(even(sample_data))
return sum(odd(sample_data))
else:
return sum(sample_data)
n= int(input())
op = sum_of_numbers(n,even)
Output: