简体   繁体   中英

Double iteration in list of tuples of tuples

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']

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]].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM