Sum of list without lowest and highest list integers (python)
<p>Trying to practice my list comprehension, but at this point my code is looking a little (too) long per line length comprehension: </p>

<pre><code>def sum_array(arr):
    return 0 if arr == None else sum(sorted(arr)[1:-1] for x in range(len(arr or [])-2)) 
</code></pre>

<p>Objective is to calculate sum of integers minus the min and max. If array is empty, <code>None</code>, or if only 1 element exists, the function should return 0.</p>

<p>I am receivingthe following</p>

<blockquote>
  <p>TypeError: unsupported operand type(s) for +: 'int' and 'list'</p>
</blockquote>

<p>Please advise!  </p>

<p>Here's a version which meets your requirements:</p>

<pre><code>def sum_array(arr):
    return (None if len(arr) &lt;= 1 else 0) if not arr else sum(sorted(arr)[1:-1])

cases = [[j + 1 for j in range(i)] for i in range(5)]

for c in cases:
    print(c, sum_array(c))

# Requirements: Objective is to calculate sum of integers minus the min and
# max. If array is empty, None, or if only 1 element exists, the function
# should return 0.
# [] None
# [1] 0
# [1, 2] 0
# [1, 2, 3] 2
# [1, 2, 3, 4] 5
</code></pre>

python if-statement list-comprehension