ar = [[0 for j in range(m)] for i in range(n)]
def list_2D(r, c):
l = []
for i in range(r):
x = [0] * c
l.append(x)
return l
Two-dimensional lists can be accessed similar
to their one-dimensional counterpart. Instead of providing
a single pair of brackets [ ] we will use an additional set for
each dimension past the first.
#The below code demonstrates
heights = [["Noelle", 61], ["Ali", 70], ["Sam", 67]]
#To access "Noelle" or her age, would type the following
noelles_height = heights[0][1]
print(noelles_height)
#This would print out:
61
Here are the index numbers to access data for the list heights:
Element Index
"Noelle" heights[0][0]
61 heights[0][1]
"Ali" heights[1][0]
70 heights[1][1]
"Sam" heights[2][0]
67 heights[2][1]