【发布时间】:2017-04-17 17:09:57
【问题描述】:
下午好, 我正在尝试垂直打印 8 个列表,但似乎找不到正确的格式。我知道您可以通过...垂直打印列表
for x in list:
print(x)
但是,我不知道如何在一行中垂直打印多个列表。 我在想一些类似的事情......
for L in range(0,7):
print(" ", end="")
try:
for column in tableaus:
print("{***}".format(str(tableaus[0][8])))
except IndexError:
raise RuntimeError("error occurred creating the tableaus")
Tableaus,如果单独打印,看起来像这样:
[[K♠, 5♠, 10♥, 2♥, 7♦, Q♣, 4♣], [Q♠, 4♠, 9♥, A♥, 6♦, J♣, 3♣], [J♠, 3♠, 8♥, K♦, 5♦, 10♣, 2♣], [10♠, 2♠, 7♥, Q♦, 4♦, 9♣, A♣], [9♠, A♠, 6♥, J♦, 3♦, 8♣], [8♠, K♥, 5♥, 10♦, 2♦, 7♣], [7♠, Q♥, 4♥, 9♦, A♦, 6♣], [6♠, J♥, 3♥, 8♦, K♣, 5♣]]
我希望它看起来更像这样:
l l l l l l l l
i i i i i i i i
s s s s s s s s
t t t t t t t t
. . . . . . . .
. . . . 5 6 7 8
1 2 3 4
【问题讨论】:
-
这里有一个提示:使用
zip获取需要在元组中打印的每一行。 -
整个for循环可以这样完成:
for L in tableaus: try: print([column for column in L]))...etc