Fetching all the strings in a python list of lists
<p>I have this list of lists</p>

<pre><code>a = [[1,2,3,4,'normal'],[1,2,3,4,'abnormal'],[1,2,3,4,'normal'],[1,2,3,4,'ab
normal'],[1,2,3,4,'normal'],[1,2,3,4,'abnormal'],[1,2,3,4,'abnormal'],[1,2,3,4,'
abnormal']]
</code></pre>

<p>I want to extract all the strings perse I have no idea what these strings might be, and count each string occurance.
Is there a simple loop instruction to do that ? </p>

<p>If you want to count the number of occurrences and keep track of the string, loop over each item and add it to a dictionary</p>

<pre><code>a = [[1,2,3,4,'normal'],[1,2,3,4,'abnormal'],[1,2,3,4,'normal'],[1,2,3,4,'abnormal'],[1,2,3,4,'normal'],[1,2,3,4,'abnormal'],[1,2,3,4,'abnormal'],[1,2,3,4,'abnormal']]

new={}
for b in a:
    for item in b:
        if type(item) is str:
            if item in new:
                new[item]+=1
            else:
                new[item]=1
print(new)
</code></pre>

python list