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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -