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