Copying part of a list in Python
<p>I've searched for a relevant thread on how to do this but I cannot find anything.</p>

<p>I have an array:</p>

<pre><code>x = [a,a,a,b,a,a]
</code></pre>

<p>I want to copy the elements of the array into a new array until I find 'b'. I tried to do this with a loop but I get an error that "y is not defined", I tried initializing y but that didn't work either. Any ideas? I'm sure there is a better way to do this.</p>

<pre><code>for ii in x:
    if x[ii].find(num) == 0:
        break
    else:
        y[ii] = x[ii]
</code></pre>