list_values = [...]
gen = (
list_values[pos : pos + bucket_size]
for pos in range(0, len(list_values), bucket_size)
)
Is there a way to make this work if list_values is a generator instead? My objective is to reduce RAM usage.
I know that I can use itertools.islice to slice an iterator.
gen = (
islice(list_values, pos, pos + bucket_size)
for pos in range(0, len(list_values), bucket_size)
)
The problem is:
- How would I remove/substitute
len(list_values)
, which doesn't work for generators? - Will the use of islice, in this case, reduce peak RAM usage?