2014-03-26 43 views
-5

我怎麼能拒絕students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]轉彎列表到表中的Python

到:

Abe  200 

Lindsay 180 

Rachel 215 

這應該能夠爲任何規模大小列表工作。

+5

你要的「矩陣」用同樣的方法:http://stackoverflow.com/questions/22673924/how-can-i-turn-random-matrix-into-a-table – fredtantini

+0

我不清楚在你想要的最終形式上。那些字符串?字符串之間的空行是否是所需輸出的一部分?你想如何對齊第二列? – steveha

+1

整個下午你一直在問這個問題。有沒有什麼問題,你在這裏得到的優秀答案:http://stackoverflow.com/questions/22670097/turn-the-python-2d-matrix-list-into-a-table/22670113#22670113 – carlosdc

回答

2
students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)] 
for student in students: 
    print(*student, sep='\t') # python 3 

for student in students: 
    print '\t'.join(str(i) for i in student) # python 2