Challenge - 5 Problems
Array and List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ trace
intermediate2:00remaining
Trace the final list after operations
Given the following steps on a list, what is the final list?
my_list = [1, 2, 3, 4]
my_list.append(5)
my_list.pop(1)
my_list.insert(2, 10)
Intro to Computing
my_list = [1, 2, 3, 4] my_list.append(5) my_list.pop(1) my_list.insert(2, 10)
Attempts:
2 left
💡 Hint
Remember that pop removes the item at the given index and append adds to the end.
✗ Incorrect
Starting list: [1, 2, 3, 4]. After append(5): [1, 2, 3, 4, 5]. pop(1) removes element at index 1 (which is 2), so list becomes [1, 3, 4, 5]. insert(2, 10) adds 10 at index 2, resulting in [1, 3, 10, 4, 5].
🧠 Conceptual
intermediate2:00remaining
Understanding list indexing and slicing
What will be the output of the following slicing operation?
numbers = [10, 20, 30, 40, 50, 60]
print(numbers[1:5:2])
Intro to Computing
numbers = [10, 20, 30, 40, 50, 60] print(numbers[1:5:2])
Attempts:
2 left
💡 Hint
Slicing syntax is list[start:stop:step]. It includes start index but excludes stop index.
✗ Incorrect
numbers[1:5:2] means start at index 1 (20), go up to but not including index 5 (which is 60), stepping by 2. So elements at index 1 and 3 are selected: 20 and 40.
❓ Comparison
advanced2:00remaining
Compare list and array behavior
Which statement correctly describes a key difference between arrays and lists in programming?
Attempts:
2 left
💡 Hint
Think about type restrictions and flexibility of these data structures.
✗ Incorrect
Arrays typically store elements of the same type for efficient memory use. Lists are more flexible and can hold different types of elements.
❓ identification
advanced2:00remaining
Identify the error in list operation
What error will this code produce?
my_list = [1, 2, 3]
print(my_list[5])
Intro to Computing
my_list = [1, 2, 3] print(my_list[5])
Attempts:
2 left
💡 Hint
Check if the index 5 exists in the list of length 3.
✗ Incorrect
The list has indices 0, 1, and 2. Accessing index 5 is out of range, causing an IndexError.
🚀 Application
expert3:00remaining
Determine the number of elements after nested list flattening
Given the nested list below, how many elements will the flattened list contain?
Assuming flattening means combining all inner elements into one list.
nested = [[1, 2], [3, 4, 5], [6], []]
Assuming flattening means combining all inner elements into one list.
Intro to Computing
nested = [[1, 2], [3, 4, 5], [6], []]
Attempts:
2 left
💡 Hint
Count all elements inside each inner list and sum them.
✗ Incorrect
Inner lists have lengths 2, 3, 1, and 0 respectively. Total elements = 2 + 3 + 1 + 0 = 6.