[go: up one dir, main page]

0% found this document useful (0 votes)
0 views3 pages

2 June

The document discusses nested lists in Python, illustrating their structure and usage with examples. It includes operations on two-dimensional arrays (DDA), such as calculating sums of rows and columns, adding matrices, and finding the transpose. Various code snippets demonstrate these concepts and operations.

Uploaded by

Sandeep sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

2 June

The document discusses nested lists in Python, illustrating their structure and usage with examples. It includes operations on two-dimensional arrays (DDA), such as calculating sums of rows and columns, adding matrices, and finding the transpose. Various code snippets demonstrate these concepts and operations.

Uploaded by

Sandeep sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

# 2-June -2025

# Nested List ( List inside of List ) Is called nested List


# Note : In python we can define DDA using nested List
# int x[3][4] ( In c / C++)
'''
N_lst = [[1,22.5,'Hello'],[190,'Bhopal',89.88],[67.555,111]]

print(N_lst) # print complete list

for ele in N_lst:


print(ele)
'''
'''
O/P
[1,22.5,'Hello']
[190,'Bhopal',89.88]
[67.555,111]
'''
'''
# Print sub elements of nested list
N_lst = [[1,22.5,'Hello'],[190,'Bhopal',89.88],[67.555,111]]

for ele in N_lst: # ele=[1,22.5,'Hello'],[190,'Bhopal',89.88],---


for subele in ele :
print(subele,end=' ')
print()
'''
# Creation of DDA ( Matrix )
M1 = [[2,7,9],[1,3,7],[9,8,4]] # 3 X 3 DDA

# print(M1)
'''
for row in M1:
print(row)
'''
'''
for row in M1:
for ele in row:
print(ele,end=' ')
print()
'''

'''
2 7 9
1 3 7
9 8 4'''
'''
# Varying length of DDA
M1 = [[1,2,3,7],[9,3,5],[2],[6,7]]
for row in M1:
for ele in row:
print(ele,end=' ')
print()
'''
'''
1 2 3 7
9 3 5
2
6 7
'''
# program list
# 1. WAP to calculate sum of element of every row in DDA
# 2. WAP to calculate sum of element of every Column in DDA
# 3. WAP to calculate sum of Two DDA ( addition of matrices )
# 4. WAP to calculate transopose of DDA
# 5. WAP to calculate multiplication of two MATRICES
'''
# 1. WAP to calculate sum of element of every row in DDA
M1 = [[3,1,4],[5],[8,9],[2,2,3,3]]
for row in M1:
for ele in row:
print(ele,end=' ')
print(" = " , sum(row))
'''
# 2. WAP to calculate sum of element of every Column in DDA
# Assignment

# 3. WAP to calculate sum of Two DDA ( addition of matrices )


# note for matrx addition order of both matrix must be same
# otherwise addition is not possible
m1=[[1,2,3],[7,7,8],[3,4,1]]
m2=[[4,5,6],[1,1,9],[8,2,3]]
m3=[[],[],[]] # empty DDA
# m3 = m1 + m2
for i in range(3):
for j in range(3):
m3[i].append(m1[i][j]+m2[i][j])

# PRINTING
for row in m3:
for ele in row:
print(ele,end=' ')
print()

'''
m1 m2 m3
1 2 3 4 5 6 5 7 9 m3[0]
7 7 8 1 1 9 8 8 17 m3[1]
3 4 1 8 2 3 11 6 4 m3[2]
'''

You might also like