Getting min/max in a sequence


Category:
Scripts
Python
Requirements:
Seller:
Price:
-
System:
Rating:
4.5
License:

Description - Getting min/max in a sequence



Sometimes it is useful to know what is the smallest value in a sequence greater than (or equal to) some other value. Eg. max_lt([2, 3, 5, 7, 11], 6) would be 5, because 5 is greatest value in the list which is also less than 6. Following the same lines method call min_gt([3, 5, 6, 10, 12], 6) would return 10, because 10 is the smallest value in the list greater than 6. The following four simple methods implement min_gt, min_le, max_gt and max_ge, but the input must be sorted for them to work. However, Greg Jorgensen`s suggestion is much more clever. No need for sorting, just use list comprehensions with min/max.



More in Python-Getting min/max in a sequence

Following Smallest Greater Than Work However Greg