Filter list's elements by type of each element
<p>I have list with different types of data (string, int, etc.). I need to create a new list with, for example, only int elements, and another list with only string elements. How to do it?</p>

<p>Sort the list by type, and then use <code>groupby</code> to group it:</p>

<pre><code>&gt;&gt;&gt; import itertools
&gt;&gt;&gt; l = ['a', 1, 2, 'b', 'e', 9.2, 'l']
&gt;&gt;&gt; l.sort(key=lambda x: str(type(x)))
&gt;&gt;&gt; lists = [list(v) for k,v in itertools.groupby(l, lambda x: str(type(x)))]
&gt;&gt;&gt; lists
[[9.2], [1, 2], ['a', 'b', 'e', 'l']]
</code></pre>

python