I am iterating through a list and comparing each element to 2 dictionaries. The list elements are keys in the dictionaries. Some elements are in the 2 dictionaries, some are in one, some are in none.
for i in range(0,len(mylist)-1):
if mylist[i] == mydict[mylist[i]]:
print 'in dict 1'
elif mylist[i] == mydict2[mylist[i]]:
print 'in dict 2'
else: print 'not in dictionaries'
My problem is it isn't getting past the first elif statement. If it doesn't find the list element in the 2 dictionaries, it prints a key error. I can't understand it because I have another loop in another part of the code that's very similar to this and works perfectly. If a key isn't in a dictionary I want the else statement printed. Not a key error
range(0,len(mylist)-1)is the same asrange(len(mylist)-1)