Exercise 3: Count Occurrences with a While Loop — Possible Solution ==================================================================== fruits = ["apple", "pear", "apple", "banana", "pear", "apple"] counts = {} index = 0 while index < len(fruits): fruit = fruits[index] if fruit in counts: counts[fruit] += 1 else: counts[fruit] = 1 index += 1 print(counts) Output: {'apple': 3, 'pear': 2, 'banana': 1} WHY THIS WORKS AS AN ANSWER ------------------------------ The "if fruit in counts" check is doing the real work: it distinguishes "I've seen this fruit before, so add one to its existing count" from "this is the first time, so start its count at 1." Without that check, counts[fruit] += 1 on a brand-new key would raise a KeyError, since you can't add 1 to a value that doesn't exist yet. The while loop itself is the simplest shape in this whole exercise set — a single index walking a single list, no nested search required — because "does this key exist" is answered directly by the dictionary's own "in" operator rather than a manual scan, unlike searching a list or tuple for a value in the earlier exercises.