Given a list of unsorted numbers, I want to find the smallest number larger than N (if any).
In C#, I'd do something like this (checks omitted) :
var x = list.Where(i => i > N).Min();
What's a short, READABLE way to do this in Python?
Given a list of unsorted numbers, I want to find the smallest number larger than N (if any).
In C#, I'd do something like this (checks omitted) :
var x = list.Where(i => i > N).Min();
What's a short, READABLE way to do this in Python?
Other people have given list comprehension answers. As an alternative filter
is useful for 'filtering' out elements of a list.
min(filter(lambda t: t > N, mylist))