How to check if a list contains a string
<p>I need to iterate through a list and check if the value is a string or an int. Is there any easy way to do this in python?</p>

<p>For example:</p>

<p><code>[1,2,3]</code> would be true.</p>

<p><code>["a",2,3]</code> would be false.</p>

<p>Two more alternative ways using <code>lambda</code> would be:</p>

<pre><code>def contains_string(ls):
    return (True in map(lambda x: type(x)==str,ls))
</code></pre>

<p>or</p>

<pre><code>def contains_string(ls):
    return (filter(lambda x: type(x)==str,ls)!=[])
</code></pre>

<p>Sample output:</p>

<pre><code>&gt;&gt;&gt; l1 = [1,2,3]
&gt;&gt;&gt; l2 = [1,2,3,'a']
&gt;&gt;&gt; contains_string(l1)
False
&gt;&gt;&gt; contains_string(l2)
True
</code></pre>

python list