【问题标题】:how to change list ['1'],['2'],['3'] to 1,2,3 in python [closed]如何在python中将列表['1'],['2'],['3']更改为1,2,3 [关闭]
【发布时间】:2012-09-20 15:37:43
【问题描述】:

我想改变

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

成为

mynewlist = (1,2,3)

如何在 python 中做到这一点?

【问题讨论】:

标签: python list


【解决方案1】:

一个简单的列表理解就可以了:

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

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

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

【讨论】:

  • 您好 mgilson,我正在尝试让 csv 在 where 语句中使用 python 中的 odbc 类似“where id in (list)”......如果这可以解释......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 2013-03-08
  • 2017-04-18
  • 1970-01-01
  • 2019-11-30
相关资源
最近更新 更多