mardi 30 octobre 2018

Python nested IF statement not iterating the entire list

I need some help in understanding why it's not iterating the complete list and how I can correct this. i need to replace some values between list B and List A to do another process. The code is supposed to give me a final list of b = ['Sick', "Mid 1", "off", "Night", "Sick", "Morning", "Night"]. I was thinking 2 nested IF's statement because it's evaluating 2 different things. My code give me ['Sick', 'Mid 1', 'off', 'Night', 'off', 'Morning', 'Night'], which is correct on the [0], but not on element[4]. I was playing in the indentation of i = i+1, but that turned out a totally different result. thanks for your help.

a = ['Sick', 'PR', '', 'PR', 'Sick', 'PR', 'PR']
b = ["off", "Mid 1", "off", "Night", "off", "Morning", "Night"]

i = 0
for x in the_list:
    for y in see_drop_down_list:
        if x =="off":
            if y == "":
                the_list[i] = "off"

            else:
                the_list[i]=see_drop_down_list[i]
i = i + 1           
print (the_list)

Aucun commentaire:

Enregistrer un commentaire