title: GNUplot loop - best way to do this?
body: <p>I have a dictionary called <code>tmptwo</code> that looks like this:</p>
  <pre><code>{'test-test': [['2014-01-05 01:06:11', 37, 34, 0], ['2014-01-05 01:09:20', 44, 32, 11]], 'another-test': [['2014-01-05 01:06:11', 88, 76, 6], ['2014-01-05 01:09:20', 62, 9, 3]]}
  </code></pre>
  <p>I am trying to pipe this data into GNUplot over stdin. However I am struggling with writing the loop to do this.</p>
  <p>I must plot in the following order:</p>
  <ol>
  <li>the time-stamp of the first list followed by one of the three integers of key 'test-test'</li>
  <li>the time-stamp of the first list followed by one of the three integers of key 'another-test'</li>
  <li>As in 1. but with the next list</li>
  <li>As in 2. but with the next list</li>
  </ol>
  <p>Of course here there are only two keys so it was easy to explain in 4 steps the algorithm for this particular example. But in my actual script, the dictionary will have multiple keys and multiple lists (though all keys will have the same number of lists within their respective value pair) within the value (which itself is a list) of the key. Do you follow?</p>
  <p>I know there's probably an easier way of feeding the data in, but this is what I'm working with...</p>
  <p>So far my function for feeding this data into GNUplot looks like this:</p>
  <pre><code>def startPlotting(selection, gnuplot, tmptwo):
      try:        
          if selection == 'totals':
              sel = 1
          if selection == 'usable':
              sel = 2
          if selection == 'inserted':
              sel = 3
          
  
          for items in zip(*tmptwo.values()):
              for item in items:
                  gnuplot.stdin.write(&quot;%s,%i\n&quot; % (item[0],item[sel]))
              gnuplot.stdin.write(&quot;e\n&quot;)
          gnuplot.stdin.write(&quot;reset\n&quot;)
          gnuplot.stdin.flush()
  
      except (IOError, TypeError, NameError) as e:
          raise
  </code></pre>
  <p><strike>And so far, I'm  having no joy. Can you help?</strike></p>
  <h2>EDIT:</h2>
  <p>Have updated the loop in the code based on the suggestion below, however GNUplot is still error'ing out. I'm clearly unable to find the solution... Any suggestions?</p>