Convert string type array to array
<p>I have  this:</p>

<pre><code>[s[8] = 5,

 s[4] = 3,

 s[19] = 2,

 s[17] = 8,

 s[16] = 8,

 s[2] = 8,

 s[9] = 7,

 s[1] = 2,

 s[3] = 9,

 s[15] = 7,

 s[11] = 0,

 s[10] = 9,

 s[12] = 3,

 s[18] = 1,

 s[0] = 4,

 s[14] = 5,

 s[7] = 4,

 s[6] = 2,

 s[5] = 7,

 s[13] = 9]
</code></pre>

<p>How can I turn this into a python array where I can do <code>for items in x:</code> ?</p>

<p>Assuming this is one giant string, if you want <code>print s[0]</code> to print <code>4</code>, then you need to split this up by the commas, then iterate through each item.</p>

<pre><code>inputArray = yourInput[1:-1].replace(' ','').split(',\n\n')
endArray = [0]*20
for item in inputArray:
    endArray[int(item[item.index('[')+1:item.index(']')])]= int(item[item.index('=')+1:])
print endArray
</code></pre>

python python-2.7