DEV Community

Poornima Ravi
Poornima Ravi

Posted on

Python List Tutorial Day2

  1. Transpose of Matrix
  2. String Rotation
  3. Matrix - sum of all rows, sum of all cols, max number in each row, min in each row
  4. Matrix - sum of cols.,sum of leading diagonal
#1. Transpose of Matrix
l = [[10,12],
     [40,2],
     [60,3]]

Transpose = []
i = 0 
j = 0
#print(len(l[i]))
#print(len(l[j]))
while i < len(l[0]):
    list = []
    while j < len(l):
        list.append(l[j][i])
        j+=1
    Transpose.append(list)
    j=0    
    i+=1
print (l ,'Transpose:',Transpose, sep='\n')

#2. String Rotation

word = 'abcdef'
#num = 2 # --> cdefab
#num = 1 # --> bcdefa
#num = -2 # efabcd
#num = -1 # fabcde
num = int(input('Enter the Num:'))
num = num%len(word)
print(word[num:] + word[:num])

#3.Matrix -#List wise Total #List wise Maximum Value, #list wise minimum value

#List wise Total

student_marks = [[10,20,30],
                 [40,50,60],
                 [70,80,90]]

for marks_list in student_marks:
    sum = 0
    for mark in marks_list:
        sum = sum + mark
    print(sum, end=' ')
    print()

print("==============================================")


#List wise Maximum Value

student_marks = [[10,20,30],
                 [40,50,60],
                 [70,80,90]]

for marks_list in student_marks:
    max = 0
    for mark in marks_list:
        if mark > max:
            max = mark
    print('Max:',max, end=' ')
    print()

print("=============================================")

#list wise minimum value 


for marks_list in student_marks:
    min = marks_list[0]
    for mark in marks_list:
        if mark < min:
            min = mark
    print('Min:',min, end=' ')
    print()

 #4. Matrix - sum of cols,sum of leading diagonal
student_marks = [[10,20,30],
                 [40,50,60],
                 [70,80,90]]
#Sum of all columns 
#10+40+70
#20+50+80
#30+60+90
i = 0
j = 0
sum = 0
while j < len(student_marks):
    sum =0
    i=0
    while i < 3:
        sum = sum + student_marks[i][j]
        i+=1
    j+=1
    print('sum:',sum)


print('=======================================================')

#10+50+90
j = 0
sum = 0
while j < len(student_marks):
    sum = sum + student_marks[j][j]
    print(student_marks[j][j], end =' ')
    j+=1
print('sum:',sum)


print('=======================================================')
#30+50+70
i = 2
j = 0
sum = 0
while j < len(student_marks):
    sum = sum + student_marks[j][i]
    print(student_marks[j][i], end =' ')
    i-=1
    j+=1
print('sum:',sum)

Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more