Jul-02-2021, 09:20 PM
zip_longest might be useful as well. Lets you not worry about the number of columns.
from itertools import islice, zip_longest data = iter([5, 77, 1, -4, 9, 17, 13, 2, 1, 5, 63, 8]) slices = [4, 2, 4, 1] columns = (islice(data, slice) for slice in slices) for row in zip_longest(*columns, fillvalue=""): print('\t'.join(str(x) for x in row))