We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 0: Weighted Mean
Day 0: Weighted Mean
Sort by
recency
|
569 Discussions
|
Please Login in order to post a comment
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))
print(f"{sum([x*w for x,w in zip(X,W)]) / sum(W):.1f}")
This is kind of a problem where Python list comprehension shines.