Turn the Python 2D matrix/list into a table
问题 How can I turn this: students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)] into this: Abe 200 Lindsay 180 Rachel 215 EDIT: This should be able to work for any size list. 回答1: Use string formatting: >>> students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)] >>> for a, b in students: ... print '{:<7s} {}'.format(a, b) ... Abe 200 Lindsay 180 Rachel 215 回答2: Use rjust and ljust: for s in students: print s[0].ljust(8)+(str(s[1])).ljust(3) Output: Abe 200 Lindsay 180 Rachel 215 回答3: