Knowledge organisersAdditional Programming Techniques
Use of 2D arrays to emulate database tables of a collection of fields, and records
A two-dimensional (2D) array is an array of arrays, like a table or grid with rows and columns. You access elements using two indices: the first selects the row and the second selects the column. 2D arrays can be used to emulate database tables where each row is a record and each column is a field.
array[row, column] (OCR ERL) or array[row][column] (Python).journeys[3,1] = "3.5" (row 3, column 1).int() or float()) when stored as strings.total = total + float(events[i,3]).events[i,0] == date, then add int(events[i,3]) or float(events[i,3]) to total.# 2D array (list of lists in Python)
seating = [
["Alice", "Bob"],
["Cara", "Dan"]
]
print(seating[0][1]) # "Bob" (row 0, col 1)
print(seating[1][0]) # "Cara" (row 1, col 0)
# Loop through all elements
for row in range(len(seating)):
for col in range(len(seating[row])):
print(seating[row][col], end=" ")
print() # New line after each row