cycle "for" in Python
<p>I have to create a three new lists of items using two different lists.</p>

<pre><code>list_one = ['one', 'two','three', 'four','five']
list_two = ['blue', 'green', 'white']
</code></pre>

<p>So, <code>len(list_one) != len(list_two)</code></p>

<p>Now I should create an algorithm(a cycle) which can do this: 
<code>[oneblue, twoblue, threeblue, fourblue, fiveblue]</code>. Same for 'green' and 'white'.</p>

<p>I undestand that I should create three cycles but I don't know how.
I've tried to make a function like this but it doesn't works.</p>

<pre><code>def mix():
    i = 0
    for i in range(len(list_one)):
        new_list = list_one[i]+list_two[0]
        i = i+1
        return new_list
</code></pre>

<p>What am I doing wrong?</p>

<ul>
<li>return should be out of for loop.</li>
<li>No need to initialize <code>i</code> and increment it, since you are using range.</li>
<li>Also, since both list can be of variable length, don't use range. Iterate over the list elements directly.</li>
<li><code>def mix():</code> should be like <code>def mix(l_one,l_two):</code></li>
</ul>

<p>All above in below code:</p>

<pre><code>def mix(l_one,l_two):
    new_list = []
    for x in l_one:
        for y in l_two:
            new_list.append(x+y)
    return new_list

list_one = ['one', 'two','three', 'four','five']
list_two = ['blue', 'green', 'white']
n_list = mix(list_one,list_two)
print n_list
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
['oneblue', 'onegreen', 'onewhite', 'twoblue', 'twogreen', 'twowhite', 'threeblu
e', 'threegreen', 'threewhite', 'fourblue', 'fourgreen', 'fourwhite', 'fiveblue'
, 'fivegreen', 'fivewhite']

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

<p>Using List Comprehension, <code>mix()</code> function will look like below:</p>

<pre><code>   def mix(l_one,l_two):
          new_list =[x+y for x in l_one for y in l_two]
          return new_list
</code></pre>

python