Created
November 12, 2018 13:13
-
-
Save renzon/23f0724335b9944490e6fda4a1c6ec5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import zip_longest | |
def sum_prod(iter, iter2): | |
return sum(map(lambda tpl: tpl[0] * tpl[1], zip_longest(iter, iter2, fillvalue=1))) | |
def test_sum_prod(): | |
assert 0 == sum_prod([], []) | |
assert 2 == sum_prod([2], []) | |
assert 6 == sum_prod([2], [3]) | |
assert 11 == sum_prod([2], [3, 5]) | |
assert 26 == sum_prod([2, 4], [3, 5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment