-4

I need help How do you put words into a 3x3 grid

this is the code i have got so far

random.shuffle(words)
print[0-3]
print (words)
Hai Vu
  • 37,849
  • 11
  • 66
  • 93

1 Answers1

2
import random
words = ["a", "b", "c", "d", "e", "f", "g", "h", "i"]

random.shuffle(words) 

grouped = [words[i:i+3] for i in range(0, len(words), 3)]
for l in grouped:
    print "".join("{:<10}".format(x) for x in l)

Output:

e         h         b         
i         c         g         
a         d         f     

Remove the random.shuffle(words) line if you need the original a,b,c,d,etc order.

Avión
  • 7,963
  • 11
  • 64
  • 105