Interesting. Tracey Jones has a very similar question...
- Cameron Simpson <c...@zip.com.au>

On 04Nov2016 16:44, Lloyd Francis <lloydyf...@gmail.com> wrote:
Hi,

I want to write a function that will calculate and return the sum of the *n*
highest value in a list *a. *Also, when n is less than 0, the answer should
be zero, and if n is greater than the number of elements in the list, all
elements should be included in the sum.

In addition i want to write the code in a function with only one line of
code in it.
So far I have:-

def sumHighest(a, n):
lambda a, n : sum(a[:n])

This doesn't work but i want to use *lambda *and the slice in the function.

An appropriate test would be:-

input - sumHighest([1,2,3,4], 2)
output - 7

thanks L.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to