Reputation: 51
I would like to ask how can I get the same output but by applying a double list comprehension. Thank you.
a = [(('123',),('a',)),(('456',),('b',)),(('789',),('c',))]
b = [i[0] for i in a]
c = [i[0] for i in b]
output:
['123', '456', '789']
Upvotes: 3
Views: 58
Reputation: 51
As suggested by @Ch3steR, adding @rassar's comment as answer.
Why not just [i[0][0] for i in a]? Or, if you really want a double list comprehension, [i[0] for i in [j[0] for j in a]].
Upvotes: 1