Skip to content

Latest commit

 

History

History
39 lines (21 loc) · 422 Bytes

Largest_Elements.md

File metadata and controls

39 lines (21 loc) · 422 Bytes

CodeWars Python Solutions


Largest Elements

Write a program that outputs the top n elements from a list.

largest(2, [7,6,5,4,3,2,1])
# => [6,7]

Given Code

def largest(n,xs):
    pass

Solution

def largest(n,xs):
  return sorted(sorted(xs, reverse=True)[:n])

See on CodeWars.com