I've looked at a online courses, and they have examples like the following:
from itertools import count
# creates a count iterator object
iterator =(count(start = 0, step = 2))
# prints an even list of integers
print("Even list:",
list(next(iterator) for _ in range(5)))
... which you could write using range
or np.arange
. Here's another example:
# list containing some strings
my_list =["x", "y", "z"]
# count spits out integers for
# each value in my list
for i in zip(count(start = 1, step = 1), my_list):
print(i)
... which is basically just enumerate
. So my question is: can you give an example of itertools.count
and itertools.islice
that can't be done (or has to be done much more clunkily) using range
?