Let’s look at all the approaches to solving this problem, from naive to oneliners, so that they can be used in programming as needed.
Method # 1: The Naive Method
Using a loop, we continue to reinitialize the named variable if we find an element less than the previous value than the named variable and greater than K.

Output:
The original list is: [1, 4, 7, 5, 10] The minimum value greater than 6 is: 7
Method # 2: Using min ( )
+ generator expression
min ()
returns the minimum number in a sequence, and linking it to a generator expression can accomplish this task much more succinctly and therefore more useful when you need to save time.
< / p>

Output:
The original list is: [1, 4, 7, 5, 10] The minimum value greater than 6 is: 7
Method # 3: min () + filter ()
A similar approach to the method above, just to filter out numbers in the list greater than k, filter ()
instead of a generator expression is used in this approach. Works the same as above.

Output:
The original list is: [1, 4, 7, 5, 10] The minimum value greater than 6 is: 7
Method # 4: Using sort () + bisect_right ()
bisect_right ()
combined with sort ()
performs the task of binary search for us and is therefore a good option to achieve a solution to this problem. bisect_right ()
because it returns a strictly larger number, not the number itself, if present in the list.

Output:
The original list is: [1, 4, 7, 5, 10] The minimum value greater than 6 is: 7