Slice all strings in a list?
<p>Is there a Pythonic way to slice all strings in a list?</p>

<p>Suppose I have a list of strings:</p>

<pre><code>list = ['foo', 'bar', 'baz']
</code></pre>

<p>And I want just the last 2 characters from each string:</p>

<pre><code>list2 = ['oo', 'ar', 'az']
</code></pre>

<p>How can I get that? </p>

<p>I know I can iterate thru the list and take <code>list[i][-2:]</code> from each one, but that doesn't seem very Pythonic.</p>

<p>Less generally, my code is:</p>

<pre><code>def parseIt(filename):
    with open(filename) as f:
        lines = f.readlines()

   result = [i.split(',') for i in lines[]]
</code></pre>

<p>...except I only want to split <code>lines[i][20:]</code> from each line (not the whole line).</p>

<p>You mentioned that you can do <code>list[i][-2:]</code> for transforming the list per your specification, but what you are actually looking for is:</p>

<pre><code>[word[1:] for word in lst]
</code></pre>

<p>Furthermore, for the code sample you provided where you are looking to seem to slice 20 characters from the beginning, the solution is the same: </p>

<pre><code>result = [i[20:].split(',') for i in lines]
</code></pre>

python string list slice