2D arrays Flashcards

1
Q

How would you create a 2D array using list comprehension in Python?

A

arr = [[0] * 4 for i in range(4)]

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

True or False: arr = [[0] * 4] * 4 is a valid way to initialize a 2D array using list comprehension?

A

False - any change to this list will effect every value in the list at the same index

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