坚持制作基本的GUI

时间:2016-11-18 23:19:27

标签: python python-3.x

首先对不起我知道这个地方真的不是要求别人为你做点什么,但我现在非常沮丧。

如果有人可以帮我转过来:

grid = [[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]

进入可输出的内容:

[1] [2] [3]

[4] [5] [6]

[7] [8] [9]

再次,非常抱歉问这个,但我只需要我能得到的所有帮助。

3 个答案:

答案 0 :(得分:0)

您可以遍历列表列表并打印每一行:

for gridRow in grid:

    print(gridRow)

获取以下输出

[[1], [2], [3]]
[[4], [5], [6]]
[[7], [8], [9]]

每次迭代时需要额外的格式才能获得您想要的格式:

for gridRow in grid:

    #map(str, gridRow) is necessary because your list contains numbers
    #if they were strings, just " ".join(gridRow) would be fine
    rowOut = " ".join(map(str, gridRow))

    print(rowOut)

准确打印您的要求。

答案 1 :(得分:0)

grid = [[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]

for row in grid:
    for element in row:
        print(element, end="")
    print()

答案 2 :(得分:0)

使用stdio,您可以打印出所需格式的数据。

    import stdio

    grid = [[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]

    for i in range(len(grid)):
        for j in range(len(grid)):
            stdio.write(str(grid[i][j]))
        stdio.writeln("\n")

[1] [2] [3]

[4] [5] [6]

[7] [8] [9]