Sort by

recency

|

569 Discussions

|

  • + 0 comments

    def weightedMean(X, W): # Write your code here we = [(x*w) for x,w in zip(X,W)] weight = 0 for item in we: weight += item print(round(weight/sum(W),1))

  • + 0 comments

    print(f"{sum([x*w for x,w in zip(X,W)]) / sum(W):.1f}")

  • + 0 comments

    This is kind of a problem where Python list comprehension shines.

  • + 0 comments
    def weightedMean(X, W):
        product = sum(list(map(lambda n: n[1] * W[n[0]], enumerate(X))))
        print(f"{product / sum(W):.1f}")
    
  • + 0 comments
    def weightedMean(X, W):
        # Write your code here
        multi = [a * b for a, b in zip(X, W)]
        
        print(round(sum(multi)/sum(W), 1))