by_department(employees) where each employee is a (name, department) tuple, returning a plain dict mapping department → list of names in input order. Use collections.defaultdict(list) to avoid the if-key-missing dance, but convert to a normal dict before returning.by_department([('Ana', 'Eng'), ('Raj', 'Sales'), ('Kim', 'Eng')]){'Eng': ['Ana', 'Kim'], 'Sales': ['Raj']}Names accumulate per department.
groups[dept].append(name) never KeyErrors on a defaultdict.
dict() strips the default factory.