简体   繁体   中英

How can I modify my for loop so that it extracts the correct data

thread_list = ['DWr','Idle','MulWr','Lock']
Target_list = ['0','0','0','1']
trd_coor = [26,10,51,10,226,10,251,10]
mem_coor = [10,215,35,215,60,215,85,215]
targ_1 = ['write','unchachable']
count_T = 0
count_X1 = 0
count_Y1 = 0
count_target = 0
count_target_1 = 0
count_dash_T = 0
T = []
trd_Y1 = []
count_dash_T_list = [0,1,2,3]
for i in trd_coor[1::2]:
    Y1 = i
    trd_Y1.append(Y1)
for i in range(0,len(count_dash_T_list)):
    target = Target_list[count_target]
    count_target += 1
    print(target)
    for i in targ_1:
        if (target == '0'):
            if (i == 'write'):
                X2 = mem_coor[0]
                Y2 = mem_coor[1]
        elif (target == '1'):
            if (i == 'uncachable'):
                X2 = mem_coor[2]
                Y2 = mem_coor[3]
            else:
                break
                    
    print(X2)
    print(Y2)

When the element in target_list is 1 I want the output to be 35,215 this is my current output: 0 10 215 0 10 215 0 10 215 1 10 215

and this is the output I want: 0 10 215 0 10 215 0 10 215 1 35 215

So there is two problems

    • typo with word unchachable
    • else statement with break

If you see closely then when we go into last for

 for i in targ_1:
        if (target == '0'):
            if (i == 'write'):
                X2 = mem_coor[0]
                Y2 = mem_coor[1]
        elif (target == '1'):
            if (i == 'uncachable'):
                X2 = mem_coor[2]
                Y2 = mem_coor[3]
            else:
                break

there target value is 1 so we go to elif and check if statemen. But i is write so we go to else and then break .

If You change type and remove break, then it should work

thread_list = ['DWr','Idle','MulWr','Lock']
Target_list = ['0','0','0','1']
trd_coor = [26,10,51,10,226,10,251,10]
mem_coor = [10,215,35,215,60,215,85,215]
targ_1 = ['write','unchachable']
count_T = 0
count_X1 = 0
count_Y1 = 0
count_target = 0
count_target_1 = 0
count_dash_T = 0
T = []
trd_Y1 = []
count_dash_T_list = [0,1,2,3]

for i in trd_coor[1::2]:
    Y1 = i
    trd_Y1.append(Y1)
for i in range(0,len(count_dash_T_list)):
    target = Target_list[count_target]
    count_target += 1
    print(target)
    for i in targ_1:
        if (target == '0'):
            if (i == 'write'):
                X2 = mem_coor[0]
                Y2 = mem_coor[1]
        elif (target == '1'):
            if (i == 'unchachable'):
                X2 = mem_coor[2]
                Y2 = mem_coor[3]
    print(X2)
    print(Y2)

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