如何在python中将列表['1'],['2'],['3']更改为1,2,3

时间:2012-09-28 18:18:45

标签: python list

我想改变

mylist = [['1'],['2'],['3']]

mynewlist = (1,2,3)

如何在python中执行此操作?

1 个答案:

答案 0 :(得分:7)

简单的列表理解将会:

mynewlist = [int(x[0]) for x in mylist]

当然,如果你真的想要一个元组作为输出:

mynewtuple = tuple(int(x[0]) for x in mylist)