For example:
list = [1,2,3,4]
how would I get this to print something like this:
1 2
3
4
For example:
list = [1,2,3,4]
how would I get this to print something like this:
1 2
3
4
code
l=[10,20,30,40,50,60]
n=3
for i in range(len(l)):
if i==0:print(' '.join([str(elem) for elem in l[:n]]))
if i>(n-1): print(l[i])
n is the position in the list you want to end the firt line
10 20 30
40
50
60
Use the end=
parameter of the print function to stay on same line, and a normal print to create a new line according to your requirements:
L = [1,2,3,4]
for n in L:
print(n, end=' ') # will stay on same line after printing
if n>=2: print() # will go to a new line for items after 2
output:
1 2
3
4