[英]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: Output:
a
b
c
d
EDIT :编辑:
Maybe you could try the next() function in the standard library.也许你可以试试标准库中的 next() function。 Create an iterator from your list of tuples:
从您的元组列表中创建一个迭代器:
iter_list = iter(_list)
Then just pass it to the next() function:然后将其传递给 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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.