Python removal of items after iteration
<p>Why is my code not working? I can't figure it out</p>

<pre><code>matchList = [['g', 'h', 'i'], ['a', 'b', 'c'] ... ]]
myList = []

for i in match_list:
    for j in i:
        for word in first_list:
            if j in word:
                myList.append(j)
                match_list.remove(j)
</code></pre>

<p>I am getting the error <code>ValueError: list.remove(x): x not in list</code></p>

<p>EDIT:</p>

<pre><code>first_list = ['i', 'am', 'an', 'old', 'man']
</code></pre>

<p>Try this:</p>

<p><em>btw: you used <code>matchList</code> and <code>match_list</code> in your post. I corrected that for my answer to make it consistent.</em></p>

<pre><code>matchList = [['g', 'h', 'i'], ['a', 'b', 'c']]
myList = []
first_list = ['i', 'am', 'an', 'old', 'man']
for i in matchList:
    for j in i:
        for word in first_list:
            if j in word:
                myList.append(j)
                for s in myList:
                    if s in i:
                        i.remove(s)
print(myList)
['i', 'a', 'a', 'a']
print(matchList)
[['g', 'h'], ['b', 'c']]
</code></pre>

python