-4

I have a list consisting of 150 integers, each one ranging from 1 to 80. I want to print the list with the following format:

x01, x02, x03, x04, x05, 
x06, x07, x08, x09, x10,
x11, x12, x13, x14, x15, 
x16, x17, x18, x19, x20, 
...
...
...

In other words I want to print the numbers in groups of 5. How do I do that?

Aventinus
  • 1,322
  • 2
  • 15
  • 33

1 Answers1

0
l = [ random.randint(1,80) for i in range(150)]

l = [l[i:i + 5] for i in range(0, len(l), 5)]
for el in l:
    print(el)

[55, 55, 66, 73, 17]
[12, 76, 72, 22, 46]
....................
[70, 29, 62, 39, 54]
[65, 73, 7, 55, 37]
LetzerWille
  • 5,355
  • 4
  • 23
  • 26