Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is an array?
An array is a collection of items stored at contiguous memory locations. Think of it like a row of mailboxes where each mailbox holds one item and has a number (index) to find it quickly.
Click to reveal answer
beginner
How is a list different from an array?
A list is like a flexible container that can hold items of different types and can grow or shrink in size. An array usually holds items of the same type and has a fixed size.
Click to reveal answer
beginner
What does 'index' mean in arrays and lists?
An index is a number that shows the position of an item in an array or list. It usually starts at 0, so the first item is at index 0, the second at index 1, and so on.
Click to reveal answer
intermediate
Why do arrays have fixed size?
Arrays have fixed size because they reserve a block of memory all at once. This makes accessing items fast but means you can't add more items than the size you set.
Click to reveal answer
beginner
Give a real-life example of a list.
A shopping list is a good example. You can add or remove items anytime, and the list can have different types of things like fruits, bread, or cleaning supplies.
Click to reveal answer
What is the starting index of an array in most programming languages?
A1
B0
C-1
DDepends on the language
✗ Incorrect
Most programming languages start array indexes at 0, meaning the first element is at position 0.
Which of these is true about lists compared to arrays?
ALists have fixed size
BLists always hold only numbers
CLists can change size dynamically
DLists store items in random order
✗ Incorrect
Lists can grow or shrink as needed, unlike arrays which usually have a fixed size.
If you want to access the third item in a list, which index do you use?
A2
B3
C1
D0
✗ Incorrect
Since indexing starts at 0, the third item is at index 2.
Why might you choose an array over a list?
AWhen you need fast access and fixed size
BWhen you want to store different types of data
CWhen you want to add items anytime
DWhen you want to store items in no order
✗ Incorrect
Arrays provide fast access because of fixed size and contiguous memory.
Which of these is NOT a characteristic of arrays?
AFixed size
BContiguous memory storage
CIndexed access
DCan hold different data types easily
✗ Incorrect
Arrays usually hold items of the same data type, not different types.
Explain what arrays and lists are, using a real-life analogy.
Think about how you organize things at home or in daily life.
You got /3 concepts.
Describe the main differences between arrays and lists.
Focus on size and type flexibility.
You got /4 concepts.
Practice
(1/5)
1. What is the position of the first item in an array or list?
easy
A. 0
B. 1
C. Depends on the list size
D. Last position
Solution
Step 1: Understand list indexing
Arrays and lists start counting positions from zero, not one.
Step 2: Identify the first position
The first item is always at position 0 in the list.
Final Answer:
0 -> Option A
Quick Check:
First position = 0 [OK]
Hint: Remember counting starts at zero in lists [OK]
Common Mistakes:
Thinking first position is 1
Confusing position with size
Assuming last position is first
2. Which of the following is the correct way to add an item 'apple' to a list named fruits in Python?
easy
A. fruits.insert('apple')
B. fruits.add('apple')
C. fruits.append('apple')
D. fruits.push('apple')
Solution
Step 1: Recall Python list methods
To add an item at the end of a list, Python uses the append() method.
Step 2: Match method to syntax
fruits.append('apple') correctly adds 'apple' to the list.
Final Answer:
fruits.append('apple') -> Option C
Quick Check:
Use append() to add items [OK]
Hint: Use append() to add items at list end [OK]
Common Mistakes:
Using add() which is for sets
Using push() which is JavaScript
Using insert() without position
3. What will be the output of this Python code?
numbers = [10, 20, 30, 40]
print(numbers[2])
medium
A. 30
B. 20
C. 40
D. 10
Solution
Step 1: Identify the index used
The code accesses numbers[2], which means the item at position 2.
Step 2: Find the item at index 2
Positions start at 0: numbers[0]=10, numbers[1]=20, numbers[2]=30.
Final Answer:
30 -> Option A
Quick Check:
Index 2 value = 30 [OK]
Hint: Count from zero to find index value [OK]
Common Mistakes:
Counting from 1 instead of 0
Confusing index with value
Choosing last item by mistake
4. Find the error in this Python code that tries to print the last item of a list named colors:
The list has 3 items at indexes 0, 1, and 2. Index 3 is beyond the last item.
Step 2: Understand error type
Accessing index 3 causes an IndexError because it is out of range.
Final Answer:
IndexError because index 3 is out of range -> Option B
Quick Check:
Index out of range = IndexError [OK]
Hint: Last index is length minus one [OK]
Common Mistakes:
Using wrong index number
Thinking index 3 is valid
Confusing error types
5. You have a list of daily temperatures: temps = [22, 19, 24, 21, 20]. How can you create a new list with only temperatures above 20 using Python list comprehension?
hard
A. [temp > 20 for temp in temps]
B. [temp for temp in temps where temp > 20]
C. [temp if temp > 20 for temp in temps]
D. [temp for temp in temps if temp > 20]
Solution
Step 1: Understand list comprehension syntax
The correct syntax is: [expression for item in list if condition].
Step 2: Apply condition to filter temps
Use temp for temp in temps if temp > 20 to select temps above 20.