Bloomberg|Phone Interview|Bucketing/Categorizing in Python

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-04-06Added By Anonymous
Source: Link
Bloomberg|Phone Interview|Bucketing/Categorizing in Python Any ideas how to solve this- Given a list of tuples ```default buckets``` and a list of scores, compare each item in ```scores``` with every tuple in ```default_bucket``` and count how many fall under such buckets. Output has to be a dictionary with tuple as keys and the count as values. ``` default_bucket = [(300,400), (401, 500), (501, 600), (601, 700), (701, 800), (801, 900), (901, 1000)] scores = [420, 410, 908, 700, 450, 310, 200, 555, 996, 1000] output = {(300, 400): 2, (401, 500): 3, (501, 600): 1, (601, 700): 1, (901, 1000): 3} ``` eg: 420 is lt 500 and gt 401 so the count of (401, 500) increases by 1. 410 falls between 401 and 500 so count increments by 1. 450 falls 401 and 500 so count increments by 1. So the count for this tuple is ``3`` .
Comments