runtime
153 / 500
question 153 Collections & Itertools · easy

How many answers has each user written?

A moderator dashboard asks for the number of answers written by a list of users, in the order it asks for them. Some of those users haven't answered anything. Write answer_counts(answers, user_ids).

Functionanswer_counts(answers, user_ids)
answersa list of dictionaries with answer_id and owner_user_id
user_idsthe users to report on, in order (a user may be asked for twice)
Returnsa list with one count per entry of user_ids; 0 for a user with no answers
Examples
callanswer_counts([{'answer_id': 9101, 'owner_user_id': 7}, {'answer_id': 9102, 'owner_user_id': 12}, {'answer_id': 9103, 'owner_user_id': 7}, {'answer_id': 9104, 'owner_user_id': 31}, {'answer_id': 9105, 'owner_user_id': 7}], [7, 31, 99])returns[3, 1, 0]
callanswer_counts([{'answer_id': 9101, 'owner_user_id': 7}, {'answer_id': 9102, 'owner_user_id': 12}, {'answer_id': 9103, 'owner_user_id': 7}, {'answer_id': 9104, 'owner_user_id': 31}, {'answer_id': 9105, 'owner_user_id': 7}], [12])returns[1]
callanswer_counts([{'answer_id': 9101, 'owner_user_id': 7}, {'answer_id': 9102, 'owner_user_id': 12}, {'answer_id': 9103, 'owner_user_id': 7}, {'answer_id': 9104, 'owner_user_id': 31}, {'answer_id': 9105, 'owner_user_id': 7}], [31, 7])returns[1, 3]

Loading your progress…

How many answers has each user written? — Python practice · Runtime