2014-01-18 35 views
0
list = [["acd",2,"b"],["c",33,"d"],["e","f",4]] 

這是我的列表。如何以三維陣列方法打印列表

我想打印像

acd 2 b 
c 33 d 
e f 4 
+1

你能證明你試過了什麼嗎?您在StackOverflow中詢問時必須顯示一些effor。 – Christian

+0

檢查此答案: [鏈接](http://stackoverflow.com/questions/4161332/how-can-i-include-python-script-in-a-html-file) –

+0

我不知道你的意思通過「打印到網站」。你想插入一個現有的HTML文件?創建一個新的?你想做出某種

的佈局,還是僅僅是什麼? –

回答

1

您可以用逗號,以保持打印輸出在同一直線上。例如

# don't name a list 'list' in python 
lst = [["acd",2,"b"],["c",33,"d"],["e","f",4]] 

for sub in lst: 
    for item in sub: 
     # for each item in the sublist, print it on a single line 
     print item, 
    # at the end of each sublist, print a new line 
    print '' 

爲了讓輸出完全一樣的問題,你的榜樣,你將不得不使用條件來檢查每個項目的規模和調整前就應該有空間量。但是這應該足以讓你開始。

1

這裏是一個一行:)

>>> print "\n".join("\t".join(map(str, item)) for item in list) 
acd 2 b 
c 33 d 
e f 4 

PS:我會重複一下@ samrap說:不要使用list作爲變量名。