L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
head = 'head'
tail = 'tail'
suppose we can and can only get the iterator of some iterable(L). and we can not know the length of L. Is that possible to print the iterable as:
'head123tail'
'head456tail'
'head789tail'
'head10tail'
My try at it is as follows.
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
head = 'head'
tail = 'tail'
slice_size = 3
i = iter(L)
try:
while True:
counter = 0
while counter < slice_size:
e = next(i)
if counter == 0:
print(head, end='')
print(e, end='')
counter += 1
else:
print(tail)
except StopIteration:
if counter > 0:
print(tail)