Simple code confusion


#1


My code isn't deleting what I specify the 'if' loop to delete. Can someone tell me why?


n=['a', 'b', 'c']

for i in range(0, len(n)):
    if i=='a':
        del n[i]
print n


#2
n=['a', 'b', 'c']

for i in range(0, len(n)):
    if n[i]=='a':
        del n[i]
print n

I think you should use n[i] in the if statement. As the i is the number in the total range, not the value tied to it. (didn't run a check but trying to think with you :wink: )


#3

thanks ! that worked !