itertools.islice
itertools.islice() slices an iterator without materializing it — useful for taking the first N items of an infinite generator.
itertools.islice() slices an iterator without materializing it — useful for taking the first N items of an infinite generator.
from itertools import islice, count
first_ten = list(islice(count(1), 10))
print(first_ten)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
islice does not support negative indices like regular slicing.