Commit 9a3c24e1 authored by DIVYANSH's avatar DIVYANSH

150020086

parents
def function1(string1,string2,listVariable):
tup1=tuple(string1); #making tuple of characters in string 1
tup2=tuple(string2); #making tuple of characters in string 2
tup3=list(zip(tup1,tup2)); #zipping the two tuples in a list
return listVariable+tup3 #returning the appended list
string1='CS251';
string2='python';
ini_list=[1,2,3,4,5];
print (ini_list); #print initial list
print (function1(string1,string2,ini_list)); #print updated list
\ No newline at end of file
def function2(listVariable,n):
def get_ele(n): #function returning lambda function in x(a tuple), n is element number
return lambda x:x[n]
g=get_ele(n); #returning a function in x to g, g will return nth element of required tuple
lis=list(map(g,listVariable)); #map is used to apply function g to each element of listVariable
stuple=sorted(listVariable,key=g); #sorting the tuple listVariable w.r.t value of function g
print (lis);
return stuple;
\ No newline at end of file
fil=open('matrix.txt','r'); #opening matrix.txt in fil variable
a=fil.read(); #taking text in a string
arr=a.split(); #splitting string in words
m=int(arr[0]); #returning number of rows in m and columns in n
n=int(arr[1]);
Arr=[[0 for j in range(n)] for i in range(m)]; #applying for loop to create the matrix in Arr
for i in range(m): #reading matrix Arr
for j in range(n):
Arr[i][j]=arr[2+(n*i)+j];
Trans=[[0 for j in range(m)] for i in range(n)]; #applying for loop to create the matrix in Trans
for i in range(n):
for j in range(m):
Trans[i][j]=Arr[j][i];
fil.close(); #closing input file
fil2=open('transpose.txt','w'); #loading file to be written
st=str(n)+" "+str(m)+'\n'; #writing number of rows and columns
fil2.write(st);
for i in range(n):
for j in range(m):
fil2.write(str(Trans[i][j])); #writing each row of transpose matrix
fil2.write(' ');
fil2.write('\n');
fil2.close(); #closing final file
\ No newline at end of file
5 5
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment