我有這個函數可以將前三列數據附加到一個新的空列表中。示例輸出:Python將多個列表添加到列表中
['red', 'blue', 'green', 'yellow', 'purple', 'black']
我想這個列表的每兩個元素包圍在自己的名單即
[['red', 'blue'], ['green', 'yellow'], ['purple', 'black']]
我怎樣才能做到這一點?謝謝。
def selection_table(table):
atts = [1,2,3]
new_table = []
for row in table:
for i in range(len(new_atts)):
new_table.append(row[atts[i]])
return new_table
非常感謝! – shutoutzilla37 2014-12-08 07:16:53