小编Gab*_*ich的帖子

在列表中加入元组

我有:

mylist = [(['a', 'b'], [1, 2]), (['c', 'd'], [3])]
Run Code Online (Sandbox Code Playgroud)

我需要一个包含字母的列表和一个包含数字的列表,像这样:

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

我做了一些努力,但是我只能得到一个包含字母的列表,而不是两个都包含:

answer = [item for sublist in mylist for item in sublist[0]]
#returns ['a', 'b', 'c', 'd']
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

标签 统计

python ×1

python-3.x ×1