from itertools import islice
def infinite_seq():
n = 1
while True:
yield n
n *= 2
gen = infinite_seq()
result = list(islice(gen, 5))
print(sum(result))
#Python
from itertools import islice
def infinite_seq():
n = 1
while True:
yield n
n *= 2
gen = infinite_seq()
result = list(islice(gen, 5))
print(sum(result))
2