Katkat

Compute Averages of Unique Numbers in Dictionary Lists

TikTokData Scientist · Onsite

Last updated

This question evaluates data manipulation and aggregation skills, focusing on handling duplicate values within collections and computing numerical summaries of list data.

Scenario

Python tech screen: given a dictionary mapping keys to numeric lists, e.g., {'a':[1,2,1],'b':[1,2,3]}, compute the average of each list after removing duplicates.

Question

Write Python code that takes any such dictionary and returns a new dictionary whose values are the average of the unique numbers in each original list.

Hints

Deduplicate each list (set or list(dict.fromkeys())), then take the mean.