Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-176

Metric Aggregation Weights

Problem

Return the weighted average of the metrics: sum(metric * weight) / sum(weight).

The lists are zipped, so the shorter one determines the terms. Return 0.0 when the weights sum to 0.

Hint

Compute the weight sum once, then normalize the weighted total by it.

Test cases

case 1
in: [[0.5,1],[1,3]]
expected: 0.875
case 2
in: [[1,2],[0,0]]
expected: 0
case 3
in: [[0.4],[2]]
expected: 0.4
case 4
in: [[],[]]
expected: 0
Starter codePython
def metric_aggregation_weights(metrics, weights):
    # Your code here
    pass

4 test cases · run your code against them in the editor