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>Here is the solution:   </p>

<pre><code>count = 0
str_list = []
for arr in a:
    for ele in arr:
        if isinstance(ele, str):
            count += 1
            str_list.append(ele)
print count
</code></pre>

<p>The variable <code>count</code> holds the total number of strings in each list inside list a. While <code>str_list</code> will hold all strings</p>

<p>Here is the code snippet on repl.it: <a href="https://repl.it/Di9L" rel="nofollow">https://repl.it/Di9L</a></p>

python list