title: Comparing list to dictionary key error python
body: <p>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.  </p>
  
  <pre><code>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'
  </code></pre>
  
  <p>My problem is it isn't getting past the first <code>elif</code> 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 <code>else</code> statement printed. Not a key error</p>