FunctionRacerProblemsRace

Votes Tally

BeginnerNumPyPython

There are k candidates numbered 0 to k - 1, and votes lists the candidate chosen on each ballot. Return a list of length k where item c is how many votes candidate c received (0 if none). Hint: np.bincount has a minlength option.

Example 1

votes [1,0,1,1]
k 3
returns [1,3,0]

Candidate 0 got 1 vote, candidate 1 got 3, candidate 2 got none.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems