Multidimentional lists Flashcards
What is a two-dimensional list?
A two-dimensional list is a list that contains other lists as its elements.
What is a one-dimensional list?
A simple list whose elements are accessed using one index.
How do you create a list for a two-dimensional data with three rows and four columns with values 0?
matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
What is the output of the following code? matrix = [] matrix.append(3 * [1]) matrix.append(3 * [1]) matrix.append(3 * [1]) matrix[0][0] = 2 print(matrix)
[[2, 1, 1], [1, 1, 1], [1, 1, 1]]
Write a statement that appends value 5 into the first row in a two-dimensional list m.
m[0].append(5)
For m = [[x, x + 1, x + 2] for x in range(1, 9, 3)], m is \_\_\_\_\_\_\_. A. [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B. [[0, 1, 2], [1, 2, 3], [2, 3, 4]] C. [1, 2, 3, 4, 5, 6, 7, 8, 9] D. [0, 1, 2, 1, 2, 3, 2, 3, 4]
A. [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
What is the output of the following code? def m(m): result = 0 for i in range(0, len(m)): result += m[i] return result
def main(): x = [[2, 1], [1, 7, 1]] print(m(x[1]))
main()
9
How many elements are in m = [[x, y] for x in range(0, 4) for y in range(0, 4)]? A. 8 B. 12 C. 16 D. 32
C. 16
[[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3]]
What is a three-dimensional list?
A three-dimensional list consists of a list of two-dimensional lists
An element in a two-dimensional list can be accessed using the following syntax________.
listName[rowIndex][columnIndex]