Multidimentional lists Flashcards

1
Q

What is a two-dimensional list?

A

A two-dimensional list is a list that contains other lists as its elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a one-dimensional list?

A

A simple list whose elements are accessed using one index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a list for a two-dimensional data with three rows and four columns with values 0?

A

matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
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)
A

[[2, 1, 1], [1, 1, 1], [1, 1, 1]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write a statement that appends value 5 into the first row in a two-dimensional list m.

A

m[0].append(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
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

A. [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
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()

A

9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
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
A

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]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a three-dimensional list?

A

A three-dimensional list consists of a list of two-dimensional lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An element in a two-dimensional list can be accessed using the following syntax________.

A

listName[rowIndex][columnIndex]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly