11. Multidimensional Lists - 17 Questions # 11. Multidimensional Lists

17 Questions
Created by Y. Daniel Liang
Free
##### There are situations that demand multi-dimensional arrays or matrices. In many languages (Java, COBOL, BASIC) this notion of multi-dimensionality is handled by pre-declaring the dimensions (and limiting the sizes of each dimension). In Python, these are handled somewhat more simply. This quiz tests the knowledge of multidimensional lists in Python programming language. Build a Resume for FREE, that gets you a Job.
1. What will be displayed by the following code?

m = [, , ]
print(m)

1
2
4
7

View Answer | Discuss in forum
2. Assume m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what are len(m)?

0
1
2
3

View Answer | Discuss in forum
3. Assume m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what are len(m)?

0
1
2
3

View Answer | Discuss in forum
4. For m = [[x, x + 1, x + 2] for x in range(0, 3)], m is _______.

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

View Answer | Discuss in forum
5. For m = [[x, x + 1, x + 2] for x in range(1, 9, 3)], m is _______.

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

View Answer | Discuss in forum
6. How many elements are in m = [[x, y] for x in range(0, 4) for y in range(0, 4)]?

8
12
16
32

View Answer | Discuss in forum
7. Assume x = ((1, 2), (3, 4, 5), (5, 6, 5, 9)), what are len(x) are len(x)?

2 and 1
2 and 2
3 and 2
2 and 3

View Answer | Discuss in forum
8. Assume x = [[1, 2], [3, 4, 5], [5, 6, 5, 9]], what are len(x), len(x), and len(x)?

2, 3, and 3
2, 3, and 4
3, 3, and 3
3, 3, and 4

View Answer | Discuss in forum
9. What will be displayed by the following program?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

v = values

for row in range(0, len(values)):

for column in range(0, len(values[row])):

if v < values[row][column]:

v = values[row][column]

print(v)

3
5
6
33

View Answer | Discuss in forum
10. What will be displayed by the following program?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

v = values

for lst in values:

for element in lst:

if v > element:

v = element

print(v)

1
3
5
6

View Answer | Discuss in forum
11. What will be displayed by the following program?

values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]

for row in values:

row.sort()

for element in row:

print(element, end = " ")

print()

The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints on row 3 4 5 1 33 6 1 2
The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints two rows 1 3 4 5 followed by 1 2 6 33

View Answer | Discuss in forum
12. What will be displayed by the following code?

matrix = [[1, 2, 3, 4],

[4, 5, 6, 7],

[8, 9, 10, 11],

[12, 13, 14, 15]]

for i in range(0, 4):

print(matrix[i], end = " ")

1 2 3 4
4 5 6 7
1 3 8 12
2 5 9 13

View Answer | Discuss in forum
13. What will be displayed by the following code?

matrix = [[1, 2, 3, 4],

[4, 5, 6, 7],

[8, 9, 10, 11],

[12, 13, 14, 15]]

for i in range(0, 4):

print(matrix[i], end = " ")

1 2 3 4
4 5 6 7
1 3 8 12
2 5 9 13

View Answer | Discuss in forum
14. What will be displayed by the following program?

def m(list):

v = list

for e in list:

if v < e: v = e

return v

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

for row in values:

print(m(row), end = " ")

3 33
1 1
5 6
5 33

View Answer | Discuss in forum
15. What will be displayed by the following code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

print(data)

1
2
4
5

View Answer | Discuss in forum
16. What will be displayed the following code?

data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

def ttt(m):

v = m

for row in m:

for element in row:

if v < element: v = element

return v

print(ttt(data))

1
2
4
5

View Answer | Discuss in forum
17. What will be displayed by the following code?

points = [[1, 2], [3, 1.5], [0.5, 0.5]]

points.sort()

print(points)

[[1, 2], [3, 1.5], [0.5, 0.5]]
[[3, 1.5], [1, 2], [0.5, 0.5]]
[[0.5, 0.5], [1, 2], [3, 1.5]]
[[0.5, 0.5], [3, 1.5], [1, 2]]

View Answer | Discuss in forum