简体   繁体   English

如何在每次迭代中只打印列表中的一个元素?

[英]How can I only print one element from the list in each iteration?

thread_list = ['DWr','Idle','MulWr','Lock']
target_list = ['0','0','0','0']
trd_coor = [26,10,51,10,226,10,251,10]
mem_coor = [10,215,35,215,60,215,85,215,210,215,235,215,260,215,285,215]
targ_1 = ['write','write']
count_T = 0

for i in range(0,len(new)):
    print(i)       
    if '-T' in new[i]:
                
        if '-a' in new[i]:
            break
        else:
            #check thread type list pass if Idle and if not point to appropriate target
            count_T += 1
            #T.append(count_T)
            for x in thread_list:
            #for x in range(0,len(thread_list)):
                print(x)

I want this loop to print out the i and then from thread list example:我希望这个循环打印出 i 然后从线程列表示例:

0
DWr
1
Idle
2
MulWr
3
Lock

Use count_T as the index into thread_list .使用count_T作为thread_list的索引。

for i, item in enumerate(new)):
    print(i)       
    if '-T' in item: 
        if '-a' in item:
            break
        else:
            print(thread_list[count_t])
            count_T += 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打印此Python列表的每个元素? - How can I print each element of this Python list? 我如何从我的列表中删除第 N 个元素,直到只剩下一个元素并在 python 中打印剩余的元素 - how do i remove the Nth element from my list until there's only one element remains and print that remaining element in python python - 如何从第一个元素开始从列表中一个一个打印元素并递增直到最后一个 - How can I print an element from a list one by one starting by first element and increment until the last one in python 我如何在无限循环中将列表的每个元素 - How can I each one element of the list in the infinity loop 如何在每次迭代中仅从一个类中抽样批次 - How to sample batch from only one class at each iteration 如何生成一个假设策略来生成一个列表,该列表至少包含它从中采样的每个元素中的一个? - How can I generate a hypothesis strategy to generate a list that contains at least one of each element it samples from? 我如何从python中的列表中随机打印元素 - how can i randomly print an element from a list in python 确保对于for循环的每次迭代,只从嵌套列表中使用一个列表 - making sure only one list is used from a nested list for each iteration of a for loop 如何打印此列表中的第二个元素? - How can I print the second element in this list? 多次遍历三个列表,在每次迭代中从列表中依次选择一个元素 - Iterate through three lists multiple times sequentially picking one element from a list in each iteration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM