Quiz: Chapter 10 :Python Data Structures (Python for Everybody Specialization) Answers 2025
Question 1
What is the difference between a Python tuple and a Python list?
✅ Lists are mutable and tuples are not mutable
❌ Tuples can be expanded
❌ Lists use integers and tuples use strings
❌ Tuples don’t maintain order
🧠 Explanation:
-
Lists → mutable (can be changed)
-
Tuples → immutable (cannot be modified after creation)
Question 2
Which method works for both lists and tuples?
✅ index()
❌ append()
❌ sort()
❌ pop()
❌ reverse()
🧠 Explanation:
Tuples are immutable, so they don’t support methods that modify them.
Only index() (and count()) work on both since they don’t change data.
Question 3
What will end up in y after this code?
✅ 4
❌ 3
❌ Two-item tuple
❌ Dictionary
❌ List
🧠 Explanation:
This is tuple unpacking — x = 3, y = 4.
Question 4
In this code:
✅ A list of tuples
❌ Tuple of integers
❌ List of integers
❌ List of strings
🧠 Explanation:.items() returns something like:[('chuck', 1), ('fred', 42), ('jan', 100)]
Question 5
Which tuple is greater than x = (5, 1, 3)?
✅ (6, 0, 0)
❌ (0, 1000, 2000)
❌ (4, 100, 200)
❌ (5, 0, 300)
🧠 Explanation:
Tuple comparison is lexicographic — it compares elements left to right.
Since 6 > 5, (6,0,0) > (5,1,3).
Question 6
What does this code do?
✅ Creates a list of tuples where each tuple is a (value, key) pair
❌ Computes largest value
❌ Computes average
❌ Sorts dictionary
🧠 Explanation:
It swaps key/value order — often used for sorting by value later.
Question 7
How do we sort a list in reverse order?
✅ data.sort(reverse=True)
❌ data = data.sort(-1)
❌ data.sort.reverse()
❌ data = sortrev(data)
🧠 Explanation:list.sort(reverse=True) sorts in descending order, in place.
Question 8
How would you print ‘Wed’?
✅ print(days[2])
❌ print(days[1])
❌ print(days.get(1, -1))
❌ print(days(2))
🧠 Explanation:
Tuple indices start at 0 → index 2 = “Wed”.
Question 9
Why are there two variables (k and v) here?
✅ Because the items() method returns a list of tuples (key, value)
❌ Because dictionary keys are strings
❌ Because there are two items
❌ Because we need previous and current key
🧠 Explanation:
Each iteration unpacks a (key, value) pair from .items().
Question 10
When might you prefer a tuple over a list?
✅ For a temporary variable that you will use and discard without modifying
❌ For extending lists
❌ For string-keyed data (use dict)
❌ For in-place sorting
🧠 Explanation:
Use tuples when data is fixed and you want performance + immutability.
🧾 Summary Table
| Q# | ✅ Correct Answer | Key Concept |
|---|---|---|
| 1 | Lists mutable, tuples not | Mutability difference |
| 2 | index() | Shared non-modifying method |
| 3 | 4 | Tuple unpacking |
| 4 | List of tuples | dict.items() output |
| 5 | (6, 0, 0) | Tuple comparison |
| 6 | List of (value, key) tuples | Inverting for sorting |
| 7 | data.sort(reverse=True) | Sorting descending |
| 8 | print(days[2]) | Tuple indexing |
| 9 | items() returns tuples | Key–value iteration |
| 10 | Temporary, immutable use | When to use tuple |