简体   繁体   中英

how to iterate ONLY the first tuple in a list of tuples?

I don't know if there is a way to find the inside of a tuple of ONLY the first tuple in a list?

list = [(a, b, c, d), (d, e, f, g), (h, i, j, k)]

output:
a
b
c
d

This is what my current loop looks like:

for x in list[0]:

EDIT: edited full question.

Input:

_list = [('a', 'b', 'c', 'd'), ('d', 'e', 'f', 'g'), ('h', 'i', 'j', 'k')]

for i in _list[0]:
    print(i)

Output:

a
b
c
d

EDIT :

Maybe you could try the next() function in the standard library. Create an iterator from your list of tuples:

iter_list = iter(_list)

Then just pass it to the next() function:

In: next(iter_list)
Out: ('a', 'b', 'c', 'd')

In: next(iter_list)
Out: ('d', 'e', 'f', 'g')

In: next(iter_list)
Out: ('h', 'i', 'j', 'k')

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