小编Nic*_*unt的帖子

python从列表[元组[str]]到列表[str]

我有这样的事情:

[('a',), ('b',), ('c',),('d',)]
Run Code Online (Sandbox Code Playgroud)

我希望它是这样的:

['a', 'b', 'c', 'd']
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

p = [('a',), ('b',), ('c',),('d',)]
[el[0] for el in p]
Run Code Online (Sandbox Code Playgroud)

有没有更“Pythonic 的方式”来做到这一点?我想避免使用 for 循环,因为我的列表由 165400 个元组组成

python dictionary

0
推荐指数
1
解决办法
148
查看次数

标签 统计

dictionary ×1

python ×1