Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除嵌套列表中第二项的引号_Python - Fatal编程技术网

Python 删除嵌套列表中第二项的引号

Python 删除嵌套列表中第二项的引号,python,Python,我需要删除嵌套列表中第二项的引号。例如,更改: a = [['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]] 但它删除了第一个元素。感谢您的帮助 [[item[0], int(item[1])] for item in a] 输出:

我需要删除嵌套列表中第二项的引号。例如,更改:

a = [['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]]
但它删除了第一个元素。感谢您的帮助

[[item[0], int(item[1])] for item in a]
输出:

[['first', 41], ['second', 0], ['third', 12]]
您可以这样做:

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]]
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]]