def reduce(function, iterable, initializer=None):
it = iter(iterable)
if initializer is None:
value = next(it)
else:
value = initializer
for element in it:
value = function(value, element)
return value
a, b = 1, 10
print(reduce(lambda s, n: s + n, range(a, b+1, 2), 0))
sum = 0
i = 1
while i <= 10:
sum += i
i += 2
print(sum)
def reduce(function, iterable, initializer=None):
it = iter(iterable)
if initializer is None:
value = next(it)
else:
value = initializer
for element in it:
value = function(value, element)
return value
a, b = 1, 10
print(reduce(lambda s, n: s + n, range(a, b+1, 2), 0))
sum = 0
i = 1
while i <= 10:
sum += i
i += 2
print(sum)