Nested loop in python to produce cartesian product
<p>I am trying to loop through two list in python to get a output like this.</p>

<pre><code>list1 = [a, b, c]
list2 = [1, 2, 3]
</code></pre>

<p>So it should loop for each value of list1 over list 2. list1[a] will loop 3 times over list2 and so on till it reaches c. However, I am not getting the desired output.</p>

<pre><code>i=''
list1 = ['ABC ' + str(i)+ ' '+'1' + ' ' + '5', 'CDE '+ str(i)+ ' '+  '1'+ ' ' + '5']
list2=['123','234','456']
for c in list1:
         for i in list2:
               print c
</code></pre>

<p>Output:</p>

<pre><code>ABC  1 5
ABC  1 5
ABC  1 5
CDE  1 5
CDE  1 5
CDE  1 5
</code></pre>

<p>Desired out put should be like below: </p>

<pre><code>ABC 123 1 5
CDE 123 1 5
ABC 234 1 5
CDE 234 1 5
ABC 456 1 5
CDE 456 1 5
</code></pre>

<p>Please guide me what I am missing here, am new with this.</p>