简体   繁体   中英

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:

0
DWr
1
Idle
2
MulWr
3
Lock

Use count_T as the index into 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

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