Write a program that outputs the top n
elements from a list.
largest(2, [7,6,5,4,3,2,1])
# => [6,7]
def largest(n,xs):
pass
def largest(n,xs):
return sorted(sorted(xs, reverse=True)[:n])
Write a program that outputs the top n
elements from a list.
largest(2, [7,6,5,4,3,2,1])
# => [6,7]
def largest(n,xs):
pass
def largest(n,xs):
return sorted(sorted(xs, reverse=True)[:n])