2013-08-07 67 views
0

我有一個列表和一個元組。我知道,元組是註定不會被修改,但我需要加入與兩者之間的列表維持秩序的元組,例如..組元組和列表維護順序python

l1 = [(166L,), (155L,)] 
l2 = [0.74, 0.25] 

我想

l3 = [[166,0.74],[155,0.25]] 

我試着整理(L1 + L2),但並沒有工作給

[0.25, 0.7, (155L,), (166L,)] 

回答

3
>>> l1 = [(166L,), (155L,)] 
>>> l2 = [0.74, 0.25] 
>>> zip([x for x, in l1], l2) 
[(166L, 0.74), (155L, 0.25)] 
>>> map(list, zip([x for x, in l1], l2)) 
[[166L, 0.74], [155L, 0.25]] 
2
l3 = [[l1[i][0], l2[i]] for i in range(len(l1))] 

將工作,假設L1是由1元組,L2是由Si的單個元素,l1和l2具有相同的長度。