title: Python 3 - Key Error = 8
body: <p>I have the following error when running printDicts() in my code:</p>
  
  <pre><code>Traceback (most recent call last):
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 238, in &lt;module&gt;
      main()
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 232, in main
      choisesDict[choise]()
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 206, in printDicts
      d = add3dicts(d1,d2,d3)
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 198, in add3dicts
      addD3(list(d3.keys()))
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 194, in addD3
      return addD2(lis[1:])
    File "Desktop\PythonApplication1\PythonApplication1\exercise3.py", line 184, in addD2
      returnDic[lis[0]] = insert2(d2[lis[0]],d3[lis[0]])
  KeyError: 8
  </code></pre>
  
  <p>The code is:</p>
  
  <pre><code>def add3dicts(d1,d2,d3):
      insert3 = lambda x,y,z:tuple(set({x,y,z}))
      insert2 = lambda x,y: tuple(set({x,y}))
      returnDic = dict()
      def addD1(lis):
          if lis == []:
              return
          if(lis[0] in d2 and lis[0] in d3):
              returnDic[lis[0]] = insert3(d1[lis[0]],d2[lis[0]],d3[lis[0]])
              d2.pop(lis[0])
              d3.pop(lis[0])
          elif(lis[0] in d2):
              returnDic[lis[0]] = insert2(d1[lis[0]],d2[lis[0]])
              d2.pop(lis[0])
          elif(lis[0] in d3):
              returnDic[lis[0]] = insert2(d1[lis[0]],d3,[lis[0]])
              d3.pop(lis[0])
          else:
              returnDic[lis[0]] = d1[lis[0]]
          return addD1(lis[1:])
      def addD2(lis):
          if lis == []:
              return
          if(lis[0] in d3):
              returnDic[lis[0]] = insert2(d2[lis[0]],d3[lis[0]])
              d3.pop(lis[0])
          else:
              returnDic[lis[0]] = d2[lis[0]]
          return addD2(lis[1:])
      def addD3(lis):
          if lis == []:
              return
          returnDic[lis[0]] = d3[lis[0]]
          return addD2(lis[1:])
      addD1(list(d1.keys()))
      addD2(list(d2.keys()))
      addD3(list(d3.keys()))
      return returnDic
  
  def printDicts():
      d1 = eval(input("Please enter the first dictionary:"))
      d2 = eval(input("Please enter the second dictionary:"))
      d3 = eval(input("Please enter the third dictionary:"))
      print("The merged dictionary is:")
      d = add3dicts(d1,d2,d3)
      print(d)
      return
  </code></pre>
  
  <p>I tried everything I knew, searched the Internet and everything, and could not figure out what the error was and how to solve it.
  Is the "key" in the error related to the dictionary? If so, then what's the error? The dictionary seems to be well built. If it's not related to the dictionary, then what's the error?
  (Sorry if there are errors in English, this is not my native language ..)</p>