mercredi 21 septembre 2016

Sum of list without lowest and highest list integers (python)

Trying to practice my list comprehension, but at this point my code is looking a little (too) long per line length comprehension:

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

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.

I am receivingthe following

TypeError: unsupported operand type(s) for +: 'int' and 'list'

Please advise!

Aucun commentaire:

Enregistrer un commentaire