我如何制作3x3 Grid Python

时间:2015-10-19 19:50:07

标签: python

我如何将代码转换为3x3网格? 额外注释:在Word.txt文件中有10个5个字母的单词。

代码:

f = open('Words.txt','r')

for word in f.read().split():
    print (word)

代码显示在列表中

NIGHT
SMOKE
GHOST
TOOTH
ABOUT
CAMEL
BROWN
FUNNY
CHAIR
PRICE

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

f = open('Words.txt','r')

words = f.read().split()

for i in range(3):
    print "\t".join(words[(i*3):(i*3+3)])

就我而言:

words = ['1','2','3','4','5','6','7','8','9','0'] 

for i in range(3):
    print "\t".join(words[(i*3):(i*3+3)])

给了我:

1       2       3
4       5       6
7       8       9