title: Python: Loops for simultaneous operation, Two or possibly more?
body: <p>This question closely relates to <a href="https://stackoverflow.com/questions/3474382/how-do-i-run-two-python-loops-concurrently">How do I run two python loops concurrently?</a></p>
  
  <p>I'll put it in a clearer manner:
  I get what the questioner asks in the above link, something like</p>
  
  <pre><code>for i in [1,2,3], j in [3,2,1]:
      print i,j
      cmp(i,j) #do_something(i,j)
  </code></pre>
  
  <p>But</p>
  
  <p>L1:    for i in [1,2,3] and j in [3,2,1]:
  doesnt work</p>
  
  <p>Q1.
  but this was amusing what happened here:</p>
  
  <pre><code>    for i in [1,2,3], j in [3,2,1]:
      print i,j
  
  
  [1, 2, 3] 0
  False 0
  </code></pre>
  
  <p>Q2. How do I make something like L1 work?</p>
  
  <p>Not Multithreading or parallelism really. (It's two concurrent tasks not a loop inside a loop) and then compare the result of the two.</p>
  
  <p>Here the lists were numbers. My case is not numbers:</p>
  
  <pre><code>for i in f_iterate1() and j in f_iterate2():
  </code></pre>
  
  <p>UPDATE: abarnert below was right, I had j defined somewhere. So now it is:</p>
  
  <pre><code>&gt;&gt;&gt; for i in [1,2,3], j in [3,2,1]:
      print i,j
  
  
  
  Traceback (most recent call last):
    File "&lt;pyshell#142&gt;", line 1, in &lt;module&gt;
      for i in [1,2,3], j in [3,2,1]:
  NameError: name 'j' is not defined
  </code></pre>
  
  <p>And I am not looking to zip two iteration functions! But process them simultaneously in a for loop like situation. and the question still remains how can it be achieved in python.</p>
  
  <p>UPDATE #2: Solved for same length lists</p>
  
  <pre><code>&gt;&gt;&gt; def a(num):
      for x in num:
          yield x
  
  
  &gt;&gt;&gt; n1=[1,2,3,4]
  &gt;&gt;&gt; n2=[3,4,5,6]
  &gt;&gt;&gt; x1=a(n1)
  &gt;&gt;&gt; x2=a(n2)
  &gt;&gt;&gt; for i,j in zip(x1,x2):
      print i,j
  
  
  1 3
  2 4
  3 5
  4 6
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>[Solved]</p>
  
  <blockquote>
    <p>Q3. What if n3=[3,4,5,6,7,8,78,34] which is greater than both n1,n2.
    zip wont work here.something like izip_longest?
    izip_longest works good enough.</p>
  </blockquote>