1
my_list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven']
使用Python一个“矩阵”式的格式,我需要显示为列表:1.4.3列表Python中
one, two, three
four, five, six
seven
我需要的是灵活,因为该列表会经常改变。
my_list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven']
使用Python一个“矩阵”式的格式,我需要显示为列表:1.4.3列表Python中
one, two, three
four, five, six
seven
我需要的是灵活,因为该列表会经常改变。
def matprint(L, numcols):
for i,item in enumerate(L):
print item,
if i and not (i+1)%numcols:
print '\n',
>>> my_list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven']
>>> matprint(my_list, 3)
one two three
four five six
seven