Splitting up a list into a 2D list using tabs and spaces
<p>I am trying to split up a python list into a 2D list starting with the following</p>

<pre><code>testList = ["Color BlueÂ»Temperature WarmÂ»Gender Male",
            "Color GreenÂ»Temperature WarmÂ»Gender Female"]
</code></pre>

<p>Where Â» is a tab character and the attributes (color, temp, gender) have a tab before them and the specifics (blue, warm, male) have a space before them.</p>

<p>I would like to ignored the attributes and create a 2D list like</p>

<pre><code>newList = [["Blue", "Warm", "Male"], ["Green", "Warm", "Female"]]
</code></pre>

<p>but I cannot figure out how to do this using the <code>split()</code> or <code>strip()</code> string methods.</p>

<p>Here's (another) way to do it:</p>

<pre><code>testList = ["Color Blue Temperature Warm    Gender Male",
            "Color Green    Temperature Warm    Gender Female"]

newList = [[subitem.split()[-1] for subitem in item.split('\t')]
                                    for item in testList]

print(newList)  # -&gt; [['Blue', 'Warm', 'Male'], ['Green', 'Warm', 'Female']]
</code></pre>

python list split strip