PCEP-30-02: Data Collections

Try 10 focused PCEP-30-02 questions on Data Collections, with explanations, then continue with IT Mastery.

On this page

Open the matching IT Mastery practice page for timed mocks, topic drills, progress tracking, explanations, and full practice.

Try PCEP-30-02 on Web View full PCEP-30-02 practice page

Topic snapshot

FieldDetail
Exam routePCEP-30-02
Topic areaBlock 3: Data Collections - Tuples, Dictionaries, Lists, and Strings
Blueprint weight25%
Page purposeFocused sample questions before returning to mixed practice

How to use this topic drill

Use this page to isolate Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings for PCEP-30-02. Work through the 10 questions first, then review the explanations and return to mixed practice in IT Mastery.

PassWhat to doWhat to record
First attemptAnswer without checking the explanation first.The fact, rule, calculation, or judgment point that controlled your answer.
ReviewRead the explanation even when you were correct.Why the best answer is stronger than the closest distractor.
RepairRepeat only missed or uncertain items after a short break.The pattern behind misses, not the answer letter.
TransferReturn to mixed practice once the topic feels stable.Whether the same skill holds up when the topic is no longer obvious.

Blueprint context: 25% of the practice outline. A focused topic score can overstate readiness if you recognize the pattern too quickly, so use it as repair work before timed mixed sets.

Sample questions

These questions are original IT Mastery practice items aligned to this topic area. They are designed for self-assessment and are not official exam questions.

Question 1

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A student runs this code to build a short tag from a product code. What is the output?

code = "AB12C"
print(code[0] + code[3] + code[4])

Options:

  • A. A2C

  • B. B2C

  • C. AB1

  • D. A1C

Best answer: A

Explanation: Python strings are zero-indexed. In "AB12C", index 0 is A, index 3 is 2, and index 4 is C, so concatenating those characters prints A2C. The program uses exact character positions, not the first three characters.

Python strings use zero-based indexing, so the first character is at position 0, not 1. For code = "AB12C", the characters are A at index 0, B at 1, 1 at 2, 2 at 3, and C at 4. The print() call joins the characters taken from indexes 0, 3, and 4.

  • code[0] -> A
  • code[3] -> 2
  • code[4] -> C

Putting them together produces A2C. Wrong choices usually come from counting positions starting at 1 or selecting the wrong middle index.

  • AB1 uses the first three characters, but the code selects positions 0, 3, and 4.
  • B2C treats indexing as if it starts at 1, but Python strings start at 0.
  • A1C chooses index 2 for the middle character, while the code uses index 3.

Question 2

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A beginner wants to remove the "city" entry from a dictionary, but the program raises TypeError: 'dict' object is not callable.

student = {"name": "Mia", "city": "Paris", "age": 19}
del student("city")
print(student)

Assume the key exists. What is the best fix?

Options:

  • A. Change it to student["city"] = None

  • B. Change it to del student["Paris"]

  • C. Change it to del student["city"]

  • D. Change it to student.remove("city")

Best answer: C

Explanation: The error happens because parentheses after a dictionary name mean a function call. A dictionary key is deleted with del and square brackets around the key, so del student["city"] is the correct fix.

Dictionaries are accessed and changed by key using square brackets. In the shown code, student("city") uses parentheses, so Python treats student like a function call. Because student is a dictionary, that causes TypeError: 'dict' object is not callable.

To remove an existing key with del, write del student["city"]. That tells Python to delete the entry whose key is "city". Assigning None would keep the key, and using a list method like remove() does not work on dictionaries.

The key takeaway is that dictionary deletion uses a key in brackets, not parentheses.

  • Setting the value to None changes the value but does not remove the key from the dictionary.
  • Using remove() fails because remove() is a list method, not a dictionary method.
  • Deleting "Paris" fails because that is a value in the dictionary, not the key being removed.

Question 3

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

The list words is already defined:

words = ["cat", "dog", "bird"]

A student wants to use a for loop to print the length of each word on a separate line. Which code fragment does this correctly?

Options:

  • A. ```python for word in len(words): print(len(word))

- B. ```python
for word in words:
    print(len(word))
  • C. ```python for word in words: print(words[word])

- D. ```python
for word in words:
    print(len(words))

Best answer: B

Explanation: A for loop over a list gives you each element directly, one at a time. Since each element in words is a string, calling len(word) inside the loop prints each word’s length on its own line. That matches the requirement exactly.

When you write for word in words:, Python assigns each list element to word during the loop. In this case, word becomes "cat", then "dog", then "bird". Because each element is a string, len(word) correctly measures that specific string and prints its length.

A common beginner mistake is confusing the current element with the whole list or with an index. Direct list iteration gives you the value itself, so the loop variable should be treated as one item from the list. That is why using len(word) works, while using the list length or trying to index the list with a string does not. The key idea is to process each list element inside the loop body.

  • Using len(words) as the iterable fails because it is a single integer, not a list or other iterable.
  • Printing len(words) inside the loop repeats the total number of items, not each word’s length.
  • Using words[word] is incorrect because word is a string element, not a numeric list index.

Question 4

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A beginner is updating a shopping-list program. The list items may contain any number of products, but it is guaranteed to be non-empty. One part of the program must print the last item, and another part must loop through every valid index. Which TWO code snippets correctly use len() for those tasks?

Options:

  • A. print(items[len(items)])

  • B. for i in range(len(items)): print(items[i])

  • C. for i in range(1, len(items)): print(items[i])

  • D. for i in range(len(items) + 1): print(items[i])

  • E. print(items[len(items) - 1])

Correct answers: B and E

Explanation: len(items) returns how many elements are in the list, not the last index. Because Python lists use zero-based indexing, the last item is at len(items) - 1, and range(len(items)) gives all valid indices.

The key idea is the difference between a list’s length and its index positions. If a list has len(items) elements, its valid indices start at 0 and end at len(items) - 1. That is why the last element is accessed with items[len(items) - 1].

For loop logic, range(len(items)) is useful because it generates exactly these valid indices: 0, 1, 2, ... , len(items) - 1. Using those values as items[i] keeps every access in bounds. If you try items[len(items)], you go one position past the end. If you loop to len(items) + 1, the same out-of-range problem appears on the last iteration. The main takeaway is that len() gives a count, so you usually subtract 1 when you need the final index.

  • Using items[len(items)] fails because the index equal to the list length is out of range.
  • Starting the loop at 1 skips index 0, so it does not process every item.
  • Looping with range(len(items) + 1) eventually reaches an invalid index equal to the list length.

Question 5

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A student wants to replace a list comprehension with a regular for loop without changing the final value of result.

nums = [1, 2, 3, 4]
result = [n * 2 for n in nums if n > 2]

Which TWO code fragments are equivalent replacements?

Options:

  • A. ```python result = [] for n in nums: if n > 2: result.append(n)

- B. ```python
result = []
for n in nums:
    result.append(n * 2)
  • C. ```python result = [] for n in nums: if n > 2: result += [n * 2]

- D. ```python
result = []
for n in nums:
    if n * 2 > 2:
        result.append(n)
  • E. ```python result = [] for n in nums: if n > 2: result = [n * 2]

- F. ```python
result = []
for n in nums:
    if n > 2:
        result.append(n * 2)

Correct answers: C and F

Explanation: A list comprehension with a trailing if both filters and transforms values. An equivalent loop must start with an empty list, check n > 2, and then add n * 2 for each matching item in the original order.

The core idea is that a basic list comprehension can be rewritten as a for loop that builds a list step by step. In this case, the comprehension keeps only values where n > 2 and stores the transformed value n * 2.

result = []
for n in nums:
    if n > 2:
        result.append(n * 2)

Using result += [n * 2] inside the same if block also works, because it extends the list by one matching transformed item at a time. The wrong choices either ignore the filter, append the original value instead of the doubled one, change the condition, or overwrite the whole list during the loop.

  • The option that appends n * 2 for every item ignores the if n > 2 filter.
  • The option that checks n * 2 > 2 and appends n changes both the condition and the stored value.
  • The option that appends n after the test keeps the filter but misses the transformation.
  • The option that assigns result = [n * 2] inside the loop replaces earlier results instead of building the full list.

Question 6

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A student writes this function to build a 3 x 2 grid. They expect only the first row to change, but the program prints [[0, 7], [0, 7], [0, 7]].

def build_grid(rows, cols):
    row = [0] * cols
    grid = []
    for _ in range(rows):
        grid.append(row)
    grid[0][1] = 7
    return grid

print(build_grid(3, 2))

Which change correctly fixes the function?

Options:

  • A. Replace grid.append(row) with grid.append([0] * cols).

  • B. Replace grid.append(row) with grid.append(row * rows).

  • C. Replace grid[0][1] = 7 with grid[1][0] = 7.

  • D. Replace return grid with return grid[:].

Best answer: A

Explanation: The problem is that every row in grid refers to the same inner list. Creating a fresh list for each loop iteration fixes the shared-row issue, so only the targeted element in the first row changes.

With nested lists, grid.append(row) adds a reference to the existing row list, not a brand-new row. Because the loop appends that same inner list multiple times, all rows in grid point to the same object. When grid[0][1] = 7 runs, that single shared list changes, so every displayed row appears updated.

  • grid.append([0] * cols) creates a separate inner list each time.
  • Then grid[0][1] = 7 affects only the first row.
  • A slice like grid[:] copies only the outer list, not the inner lists.

The key fix is to stop reusing the same inner list when building the nested list.

  • Different index changes which cell is updated, but it does not remove the shared inner-list problem.
  • Outer-list slice makes only a shallow copy of the outer list, so the rows still reference the same inner list.
  • Row multiplication repeats values inside one row and changes its length instead of creating independent rows.

Question 7

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A classroom app stores supply counts in a dictionary:

items = {"notebooks": 15, "markers": 6, "folders": 9}

The key "markers" already exists. You need to change its value to 10. Which TWO statements correctly do that?

Options:

  • A. items["markers"] == 10

  • B. items.append({"markers": 10})

  • C. items.get("markers") = 10

  • D. items["markers"] = 10

  • E. items.add("markers", 10)

  • F. items.update({"markers": 10})

Correct answers: D and F

Explanation: A dictionary is mutable, so an existing key’s value can be changed in place. Direct key assignment and the update() method both replace the value for "markers" with 10.

To update a value in a dictionary, you must target the key. In Python, assigning to items["markers"] changes the value stored for that key. The update() method can also change it when you pass another dictionary containing the same key.

items["markers"] = 10
items.update({"markers": 10})

A comparison such as == only tests whether the current value matches 10; it does not modify anything. Methods like append() and add() belong to other collection types, not dictionaries. The main idea is that dictionary mutation happens through key assignment or dictionary methods designed for updates.

  • The option using == only compares values and leaves the dictionary unchanged.
  • The option using append() fails because dictionaries do not have a list-style append method.
  • The option using add() fails because add() is associated with sets, not dictionaries.
  • The option assigning to get(...) is invalid because you cannot assign to a returned value from a function call.

Question 8

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A student is testing a list loop in Python 3. What is the result when this code runs?

items = ["pen", "pencil", "eraser"]
i = 0

while i <= len(items):
    print(items[i])
    i += 1

Options:

  • A. It prints pen, pencil, then raises IndexError.

  • B. It prints pen, pencil, eraser, then raises IndexError.

  • C. It prints pen, pencil, eraser, and ends normally.

  • D. It raises IndexError before printing anything.

Best answer: B

Explanation: Lists use zero-based indexing, so a 3-item list has valid indices 0, 1, and 2. Because the loop uses i <= len(items), it prints the three items and then tries items[3], which raises IndexError.

In a list, len(items) gives the number of elements, not the last valid index. Here, len(items) is 3, but the valid indices are 0, 1, and 2. The condition i <= len(items) allows i to become 0, 1, 2, and then 3.

The loop runs like this:

  • i = 0 prints pen
  • i = 1 prints pencil
  • i = 2 prints eraser
  • i = 3 tries items[3] and fails

Python raises IndexError when direct indexing uses a position outside the list range. A common fix is to use i < len(items) instead.

  • The option ending after pencil is wrong because index 2 is valid and prints eraser.
  • The option ending normally misses that the loop still runs when i becomes 3.
  • The option raising the error immediately ignores that indices 0, 1, and 2 are accessed successfully first.

Question 9

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

What is the output of the following code?

data = [4, 2]
backup = data
data = sorted(data)
backup.append(6)
print(data)
print(backup)

Options:

  • A. [2, 4] then [4, 2, 6]

  • B. [2, 4] then [2, 4, 6]

  • C. [4, 2] then [4, 2, 6]

  • D. [2, 4, 6] then [2, 4, 6]

Best answer: A

Explanation: backup = data makes both names refer to the same original list at first. Then sorted(data) returns a new sorted list for data, while backup.append(6) changes the old list, so the two printed lists are different.

This tests the difference between creating a new list and mutating an existing one. backup = data means both variables initially reference the same list object, [4, 2]. But data = sorted(data) does not sort that list in place; it creates a new list [2, 4] and assigns that new list to data.

  • data starts as [4, 2]
  • backup points to the same original list
  • sorted(data) makes a new list [2, 4]
  • backup.append(6) mutates the original list to [4, 2, 6]

So print(data) shows the new sorted list, while print(backup) shows the mutated original list. The key takeaway is that sorted() creates a new list, but append() changes an existing one.

  • The choice showing both lines as [2, 4, 6] assumes sorted() changed the original list in place.
  • The choice showing [4, 2] first ignores that data was reassigned to the new sorted list.
  • The choice showing [2, 4, 6] for backup assumes backup automatically followed data after reassignment.

Question 10

Topic: Block 3: Data Collections - Tuples, Dictionaries, Lists, and Strings

A student wants to remove the city key from a dictionary so the program prints only the remaining entries.

profile = {"name": "Ana", "age": 21, "city": "Lima"}
profile.remove("city")
print(profile)

Which replacement for profile.remove("city") is the best fix?

Options:

  • A. profile.delete("city")

  • B. profile["city"] = None

  • C. del profile["Lima"]

  • D. del profile["city"]

Best answer: D

Explanation: To remove an entry from a dictionary, Python needs the key, not the value. del profile["city"] correctly deletes the whole "city": "Lima" pair from the dictionary.

A dictionary stores data as key-value pairs, so removing one entry means removing it by its key. In this program, city is the key and Lima is the value. The statement del profile["city"] deletes that entire pair from the dictionary.

Setting profile["city"] to None does not remove the key; it only changes the value. Using Lima with del is incorrect because Lima is not a key in the dictionary. Also, dictionaries do not have a delete() method. The main idea is to use the correct key-based deletion syntax for dictionaries.

  • Set to None changes the stored value but leaves the city key in the dictionary.
  • Delete by value fails because Lima is a value, not a dictionary key.
  • Use .delete() fails because delete() is not a valid dictionary method in Python.

Continue with full practice

Use the PCEP-30-02 Practice Test page for the full IT Mastery route, mixed-topic practice, timed mock exams, explanations, and web/mobile app access.

Try PCEP-30-02 on Web View PCEP-30-02 Practice Test

Free review resource

Read the PCEP-30-02 Cheat Sheet on Tech Exam Lexicon, then return to IT Mastery for timed practice.

Revised on Thursday, May 14, 2026