0

For example:

list = [1,2,3,4]

how would I get this to print something like this:

1 2
3
4
Big boy
  • 19
  • 3

2 Answers2

2

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
2

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 
Alain T.
  • 40,517
  • 4
  • 31
  • 51