Skip to content

Home

N min elements

Returns the n minimum elements from the provided list.

def min_n(lst, n = 1):
  return sorted(lst, reverse = False)[:n]

min_n([1, 2, 3]) # [1]
min_n([1, 2, 3], 2) # [1, 2]

More like this

Start typing a keyphrase to see matching snippets.