Compute Averages of Unique Numbers in Dictionary Lists
TikTokData Scientist · OnsiteLast 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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.