2011-02-05 18 views

Odpowiedz

14

Najprostszym sposobem, aby to zrobić jest użycie itertools.izip_longest():

for x in itertools.izip_longest(*l, fillvalue="."): 
    print " ".join(str(i) for i in x) 
3

to:

import itertools 

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

for t in itertools.izip_longest(*l): 
    print "".join("%3d" % x if x is not None else " ." for x in t) 

produkuje:

1 4 6 0 
    2 5 7 . 
    3 . 8 . 
    . . 9 .