我有一个像这样的元组列表:
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)]
答案 0 :(得分:4)
使用列表推导来获取每个元素的第二项:
new_list = [tuple(b) for a, b in old_list]