元组分组列表

2022-01-18 23:35:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样一个元组列表:

x = [('y', [1, 2]), ('y', [3, 4]), ('y', [5, 6])]

我想还给我这样的东西:

[(1, 2), (3, 4), (5, 6)]

注意:元组数可以不同,也可以是:

x = [('y', [1, 2, 3, 4]), ('y', [5, 6, 7, 8]), ('y', [9, 10, 11, 12]), ('y', [13, 14, 15, 16])]

会产生

[(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16)]