04.02 Data Structures In Python - Quiz¶
Check your understanding
-
How do you access the element in the second row, third column of a 2D list called
matrix?matrix[1][2]{ data-correct }matrix[2][3]matrix[2][1]matrix[3][2]
-
Which Python operation is used to add an element to the end of a list?
insert()add()append(){ data-correct }push()
-
In a stack implemented using a Python list, which operation removes the top element?
remove()pop(){ data-correct }delete()pull()
-
How do you safely access a dictionary value that might not exist?
- Use try/except with KeyError
- Use the
get()method { data-correct } - Check with
if key in dictfirst - All of the above
-
Which data structure would be most efficient for implementing a simple undo feature?
- Dictionary
- 2D List
- Stack { data-correct }
- Tree
-
What does this code do?
- Creates a 2D array
- Creates a simple tree structure using nested dictionaries { data-correct }
- Creates a stack
- Creates a hash table
-
When reading CSV files in Python, which module should you import?
filecsv{ data-correct }iodata
-
What is the result of
my_list.pop(1)on the list[10, 20, 30, 40]?- Returns 10, list becomes
[20, 30, 40] - Returns 20, list becomes
[10, 30, 40]{ data-correct } - Returns 30, list becomes
[10, 20, 40] - Causes an error
- Returns 10, list becomes
-
Which Python data type is used to implement hash tables?
- List
- Tuple
- Dictionary { data-correct }
- Set
-
In a 2D list representing a grade book, how would you calculate the average grade for the first student?
sum(grades[0]) / len(grades[0]){ data-correct }sum(grades) / len(grades)average(grades[0])grades[0].average()
-
What does
csv.DictReader()do compared tocsv.reader()?- Reads files faster
- Returns each row as a dictionary with column headers as keys { data-correct }
- Reads only the headers
- Automatically sorts the data
-
Which operation is used to add an element at a specific position in a Python list?
append()add()insert(){ data-correct }place()