python - Grouping list of tuples -
i have list of tuples this:
x = [('y', [1, 2]), ('y', [3, 4]), ('y', [5, 6])]
and want return me this:
[(1, 2), (3, 4), (5, 6)]
note: tuple number can vary, may also:
x = [('y', [1, 2, 3, 4]), ('y', [5, 6, 7, 8]), ('y', [9, 10, 11, 12]), ('y', [13, 14, 15, 16])]
which produce
[(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16)]
use list comprehension second item of each element:
new_list = [tuple(b) a, b in old_list]
Comments
Post a Comment