Python - Removing 1 char from a series of nested lists
<p>I've solved the problem with the code below, but I'm trying to understand a better way to strip out the zeros at the end of the each string of numbers because they throw off the calculation. The solution I have seems heavy handed, is there a more elegant way to solve this without a for loop removing the 0s?</p>

<h1>Coding Problem:</h1>

<p>Determine the average of a series of numbers like this:</p>

<blockquote>
  <p>97 143 3 149 1 181 195 76 0</p>
  
  <p>8042 4302 1273 3858 4019 8051 4831 7747 4887 768 6391 7817 2635 6203 0</p>
  
  <p>1783 218 154 360 409 929 1503 428 73 1505 1868 1625 64 1613 0</p>
</blockquote>

<pre><code>import sys
inp = sys.stdin.readlines()
lin = []

for i in inp[1:]:
    lin.append(map(int,i.split()))
</code></pre>

<p>/---Crux----</p>

<pre><code>for r in lin:
    del r[-1]
</code></pre>

<p>/-------------</p>

<pre><code>for n in lin:
print int(round((sum(n) / float(len(n))))),
</code></pre>

<p>Any other critiques and constructive criticisms are appreciated.</p>

<p>Cant you just do:</p>

<pre><code>lin=[]
for line in sys.stdin:
    lin.append([float(e) for e in line.split()[:-1]])
</code></pre>

<p>So that becomes a single line:</p>

<pre><code>lin=[[float(e) for e in line.split()[:-1]] for line in sys.stdin]
</code></pre>

<p>Then your averages become:</p>

<pre><code>avgs=[sum(e)/len(e) for e in lin]
&gt;&gt;&gt; avgs
[105.625, 5058.857142857143, 895.1428571428571]
</code></pre>

python list