lista = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for index, item in enumerate(lista, start = 1):
if index % 3 == 0:
print(item)
else:
print(item, end='')
Вывод:
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 three.py
123
456
789
Если вы хотите этот пробел, просто добавьте ''
lista = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for index, item in enumerate(lista, start = 1):
if index % 3 == 0:
print(item,'')
else:
print(item,'', end='')
Вывод:
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 three.py
1 2 3
4 5 6
7 8 9