[英]How to display 5x5 grid in Python?
I have an array/list in Python containing 25 different words with different lengths: 我在Python中有一个数组/列表,其中包含25个不同长度的单词:
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. 我想遍历数组并依次打印5行,每行包含5个字符串,我会在单词之间使用制表符将它们均匀隔开。
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. 我已经尝试过使用2D array(grid)并将单词附加到grid中的单个数组,但这似乎不起作用,因为我无法实现任何换行符。 Would I use \\n somehow? 我会以某种方式使用\\ n吗? The grid: 网格:
grid = [ 网格= [
[],[],[],[],[], [],[],[],[],[]
[],[],[],[],[], [],[],[],[],[]
[],[],[],[],[], [],[],[],[],[]
[],[],[],[],[], [],[],[],[],[]
[],[],[],[],[] [],[],[],[],[]
] ]
Is this even the right way to do this?? 这甚至是正确的方法吗?
Thank you 谢谢
items = ['Cat', 'Dog', 'Fish', .......... 'Yak']
for i in range(5):
print('\t'.join(items[i*5:i*5+5]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.