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>

<p>There are a few problems with your code:</p>

<ol>
<li><p>When you do a for loop <code>for i in ...:</code>, you do not need to initialize <code>i</code> (<code>i = 0</code>) and you should not increment it (<code>i = i + 1</code>) since Python knows that <code>i</code> will take all values specified in the for loop definition.</p></li>
<li><p>If your code indentation (indentation is very important in Python) is truly the one written above, your <code>return</code> statement is inside the for loop. As soon as your function encounters your return statement, your function will exit and return what you specified: in this case, a string.</p></li>
<li><p><code>new_list</code> is not a list but a string.</p></li>
<li><p>In Python, you can loop directly over the list items as opposed to their index (<code>for item in list_one:</code> as opposed to <code>for i in range(len(list_one)):</code></p></li>
</ol>

<p>Here is your code cleaned up:</p>

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

<p>This can be rewritten using a list comprehension:</p>

<pre><code>def mix(list_one, list_two):
    return [item+list_two[0] for item in list_one]
</code></pre>

<p>And because <code>list_two</code> has more than one item, you would need to iterate over <code>list_two</code> as well:</p>

<pre><code>def mix(list_one, list_two):
    return [item+item2 for item in list_one for item2 in list_two]
</code></pre>

python