title: PyQT adding data/information to Tabs using a Loop
body: <p>I am currently stuck trying to figure out how to correct execute a few loops for my program in order to get it to function as I want.</p>
  
  <p>Little background on the program, I have a List of Names, a List of Dictionaries, and a Dictionary. The goal is to compare the List of Dictionaries to the Dictionary to get the correct values. What i mean by this is let's say I have a group of animals (This is the List of Names, Lets call it <code>setNames</code>) and each one of these animals (<code>setNames</code>) has a different House, Food, Water, and Bed. (This is the list of dictionaries lets call it <code>setData</code>). And finally we have the correct value for each one of these dictionaries (<code>setData</code>). We'll call this <code>correct_parameters</code> . </p>
  
  <p>Since each animals has his own dictionary he has to make sure he has the correct parameter for his own dictionary.</p>
  
  <p>The program does the following.</p>
  
  <ol>
  <li>First, it will <em>"fix"</em> our List of Dictionaries (<code>setData</code>) to allow us to compare it later with our <code>correct_parameters</code></li>
  <li>Then, once our <code>setData</code> is split/striped it will begin a loop process to loop through each animal in our <code>setNames</code> list.</li>
  <li>Finally, once it's finished looping it will create a tab for each individual animal with their parameters that we're incorrect when compared.</li>
  </ol>
  
  <p>Visual Example: </p>
  
  <p><a href="https://i.stack.imgur.com/9i5u4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9i5u4.png" alt="Loop/Tab Example"></a></p>
  
  <p>To explain the image a bit more, We have our <code>setNames</code>, <code>setData</code>, and <code>Correct_parameters</code> As we see, the <code>setData</code> is compared to the <code>correct_parameters</code> and anything that is incorrect or does NOT match is printed onto the tab.</p>
  
  <p>Issue:</p>
  
  <p>My issue is that a tab gets created for every single parameter in the Incorrect data: </p>
  
  <p><a href="https://i.stack.imgur.com/TCmOM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TCmOM.png" alt="Tabs"></a></p>
  
  <p>I'm fairly new to python and i am still trying to figure out how to correct loop this function. any ideas?</p>
  
  <p>Code: </p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  
  class Window(QtGui.QWidget):
      def __init__(self, parent = None):
          super(Window, self).__init__(parent)
  
          # Create a QTabWidget where all the tabs will be held
          self.myTabs = QtGui.QTabWidget()
  
  
          # Loop through our animal names
          setNames = ['Cat', 'Dog', 'Bird']
          setData = [{'House=15': 'House=15', 'Food=2': 'Food=2', 'Water=4': 'Water=4', 'Bed=6': 'Bed=6'}, {'House=14': 'House=14', 'Food=2': 'Food=2', 'Water=5': 'Water=5', 'Bed=6': 'Bed=6'}, {'House=15': 'House=15', 'Food=8': 'Food=8', 'Water=4': 'Water=4', 'Bed=9': 'Bed=9'}]
          lst = setData
          for idx, val in enumerate(lst):
              o = {}
              for k,v in val.iteritems():
                  if '=' in k:
                      k = k.split('=')[0]
                  if '=' in v:
                      v = v.split('=')[1]
                      v = v.replace('"','')
                      v = v.strip()
                  o[k] = v
              lst[idx] = o
          count = 0
          print lst
          correct_parameter = {'House': '15', 'Food': '12', 'Water': '4', 'Bed': '4'}
          while count &lt; len(setNames):
              for number, item in enumerate(lst,0):
                  for tabName in setNames:
                      for param, correct in correct_parameter.items():
                          tabLabel = QtGui.QTextEdit()
                          tabWidget = QtGui.QWidget()
                          self.myTabs.addTab(tabWidget, tabName)
                          if item.get(param) != correct:
                              tabLabel.append('{} = {}'.format(param, item.get(param)))
                              # Set the tab widget's layout
                              tabLayout = QtGui.QVBoxLayout()
                              tabLayout.addWidget(tabLabel)
                              tabWidget.setLayout(tabLayout)
                          QtGui.QApplication.processEvents()
                          count += 1
  
  
          # Set the main layout
          mainLayout = QtGui.QVBoxLayout()
          mainLayout.addWidget(self.myTabs)
          self.setLayout(mainLayout)
  
          # Resize our window and show it
          self.resize(300, 300)
          self.show()
  
  
  import sys
  if __name__ == "__main__":
      app = QtGui.QApplication(sys.argv)
      main_window = Window()
      QtGui.QApplication.processEvents()
      main_window.show()
      sys.exit(app.exec_())
  </code></pre>