How can I get the minimum and the maximum element of a list in python
问题 If a have a list like: l = [1,2,3,4,5] and I want to have at the end min = 1 max = 5 WITHOUT min(l) and max(l) . 回答1: The fastest approach I can think of would be to sort the original list and then pick the first and last elements. This avoids looping multiple times, but it does destroy the original structure of your list. This can be solved by simply copying the list and sorting only the copied list. I was curious if this was slower than just using max() and min() with this quick example