Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想改
mylist = [['1'],['2'],['3']]
成为
mynewlist = (1,2,3)
如何在 python 中做到这一点?
一个简单的列表理解就可以了:
mynewlist = [int(x[0]) for x in mylist]
当然,如果你真的想要一个元组作为输出:
mynewtuple = tuple(int(x[0]) for x in mylist)