Update list in-place, converting 'True'/'False' elements to 1/0
<p>In python, supposed I have a list: </p>

<pre><code>l = [ 'True', 'False', 'myname', 1, 0, 'foo' ] 
</code></pre>

<p>and I want to convert the <em>strings</em> <code>'True'</code> or <code>'False'</code> to <code>1</code> or <code>0</code>, what is the best way to do this and still retain the index that the value had originally? i.e. the output would look like: </p>

<pre><code>l = [  1, 0, 'myname', 1, 0, 'foo' ]
</code></pre>

<p>You can use a for loop</p>

<pre><code>for i in l:

    if i == 'True':

        a = l.index(i)

        b = l.remove(i)

        l.insert(a, 1)

    elif i == 'False':

        a = l.index(i)

        b = l.remove(i)

        l.insert(a, 0)

print(l)
</code></pre>

python list dictionary