1

I have an array/list in Python containing 25 different words with different lengths:

items = ['Cat', 'Dog', 'Fish', .......... 'Yak']

I want to loop through the array and print 5 lines, one after the other, each line containing 5 strings I would tab between words to space them out evenly.

I have already tried using a 2D array(grid) and appending the word to individual array in grid but this does not seem to work as I cant implement any line breaks. Would I use \n somehow? The grid:

grid = [
[],[],[],[],[],
[],[],[],[],[],
[],[],[],[],[],
[],[],[],[],[],
[],[],[],[],[]
]

Is this even the right way to do this??

Thank you

Nalyd
  • 95
  • 1
  • 16

1 Answers1

0
items = ['Cat', 'Dog', 'Fish', .......... 'Yak']
for i in range(5):
  print('\t'.join(items[i*5:i*5+5]))
R Nar
  • 5,465
  • 1
  • 16
  • 32
  • Thank you very much this worked well and is 10x simpler than whatever the hell i was doing. :) – Nalyd Oct 21 '15 at 16:36
  • no problem :) you could also replace the `for i in range(5):` with `for i in range(0,25,5)` to get rid of the `i*5`, it looks a lot cleaner – R Nar Oct 21 '15 at 16:37