3 ms·
If you are wondering how to make a lazy take() in python, here is one solution: def take(num): def gen(iterable): for i, item in enumer
by bubulle 11y ago
If you are wondering how to make a lazy take() in python, here is one solution:
def take(num):
def gen(iterable):
for i, item in enumerate(iterable):
if i == num:
break
yield item
return gen
and then
list(take(3)(range(100)) == [0, 1, 2]