事实上我试着这样做。
我有班级名片
class Card(object):
def __init__(self, value, folldown,canMove):
self.value = value
self.folldown = folldown
self.canMove=canMove
我用它打印
for i in range(len(cards)):
for j in range(len(cards[i])):
print cards[i][j].value
我想打印不同尺寸的{2}列表a=[[0, 1], [0, 1, 2], [0, 1, 2, 3]]
我希望像这样打印
0 0 0
1 1 1
2 2
3
我试图像这样打印
for i in range(len(a)):
for j in range(len(a[i])):
print a[i][j]
但结果是
0
1
0
1
2
0
1
2
3
答案 0 :(得分:2)
a = [[0, 1], [0, 1, 2], [0, 1, 2, 3]]
print '\n'.join(['\t'.join([str(x[i]) if len(x) > i else '' for x in a]) for i in range(len(max(a)))])
#0 0 0
#1 1 1
# 2 2
# 3
答案 1 :(得分:1)
另一个一线解决方案
a = [[0, 1], [0, 1, 2], [0, 1, 2, 3]]
from itertools import izip_longest
print "\n".join(("\t".join(map(str,l)) for l in izip_longest(*a, fillvalue="")))
你得到:
0 0 0 1 1 1 2 2 3