• + 1 comment

    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 3
    def weighted_mean(numbers, weights):
        total = sum([num*weight for num,weight in zip(numbers,weights)])
        print(round(total / sum(weights),1))
    
    numbers = int(input()) # Not needed; so overwrite var with next input
    numbers = map(float, input().split())
    weights = list(map(int, input().split()))
    
    weighted_mean(numbers, weights)