2014-04-15 28 views
0

我需要刪除嵌套列表中第二項的引號。例如,更改:刪除嵌套列表中第二項的引號

a = [['first', '41'], ['second', '0'], ['third', '12']] 

到:

[['first', 41], ['second', 0], ['third', 12]] 

我試圖

[map(int, [n[1]]) for n in a] 
[[41], [0], [12], [0], [45], [17], [3], [10], [1], [19], [98], [0]] 

但它消除的第一要素。任何幫助表示讚賞。

回答

0

你可以做到這一點是:

a = [['first', '41'], ['second', '0'], ['third', '12']] 
a = [[i[0], int(i[1])]for i in a] 

>>> print a 
[['first', 41], ['second', 0], ['third', 12]] 
2
[[item[0], int(item[1])] for item in a] 

輸出:

[['first', 41], ['second', 0], ['third', 12]]