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.
Awesome with the list comprehension and zip(). Though, some minor improvements:
No need for .strip()
.split(' ') can just be .split() since it defaults to a space as the delimiter
Since the N var isn't used anyway, can just immediately overwrite the var with the next input
Slightly modified to be portable w/ portion turned into a function:
# Python 3defweighted_mean(numbers,weights):total=sum([num*weightfornum,weightinzip(numbers,weights)])print(round(total/sum(weights),1))numbers=int(input())# Not needed; so overwrite var with next inputnumbers=map(float,input().split())weights=list(map(int,input().split()))weighted_mean(numbers,weights)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 0: Weighted Mean
You are viewing a single comment's thread. Return to all comments →
Awesome with the list comprehension and
zip()
. Though, some minor improvements:.strip()
.split(' ')
can just be.split()
since it defaults to a space as the delimiterN
var isn't used anyway, can just immediately overwrite the var with the next inputSlightly modified to be portable w/ portion turned into a function: