2d list in python
ar = [[0 for j in range(m)] for i in range(n)]
Source: nullorempty.org
2d list in python
def list_2D(r, c): l = [] for i in range(r): x = [0] * c l.append(x) return l
accessing 2d list in python
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]