Removing characters from indices within multiple lists
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p>

<p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p>

<pre><code>f = ['yes', 'no', 'tot', 'foop\n']
p = ['ick', 'throw', 'tamp', 'lap\n']

L = []

L.append(f)
L.append(p)
</code></pre>

<p>So now L is:</p>

<pre><code>L = [['yes', 'no', 'tot', 'foop\n'], ['ick', 'throw', 'tamp', 'lap\n']]
</code></pre>

<p>How would I go about getting writing a loop that would get rid of the \n at the end of every 4th index, within both lists (that could also be extended for more than just the 2 lists I have above in the list)? </p>

<p>I just want it to re-return L, without those \n's at the end of those last indices. </p>

<p>For getting each 4th element from the list use this part: <code>i[3::4]</code></p>

<p>For removing last two symbols from item: <code>x[:-1]</code></p>

<p>The output script:</p>

<pre><code>for i in L:
    i[3::4] = [ x[:-1] for x in i[3::4]]
</code></pre>

<p>Result:</p>

<blockquote>
  <p>[['yes', 'no', 'tot', 'foop'], ['ick', 'throw', 'tamp', 'lap']]</p>
</blockquote>

python list