On Thu, Sep 17, 2009 at 8:06 AM, Rich Lovely <roadier...@googlemail.com> wrote: > 2009/9/17 Rayon <evosw...@hotmail.com>: >> I need to find the max and min value from some floats in a array:
> Depending on the size of the array, there's two methods: Using the > max and min builtin functions, which will be faster for small arrays, > or hand-coding a single pass function, which might be faster for > arrays above a certain size. Why do you expect a hand-coded function to scale better? I would expect them both to be O(n). > def minmax2(a): > #This only takes one pass, but is python, which is not as fast as C code. > #This also has the advantage of allowing you to easily customize > your lookups and comparisons min() and max() both take key= parameters allowing you to customize the comparison. > Other techniques to consider: If order is not important, take the > first and last values after sorting (or after sorting a copy). Sorting is O(n log n) so this will have relatively worse performance with larger arrays. Kent _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor