Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It doesn't bother you that you're checking `min is None` even after you know it can't be (i.e., after one loop iteration)? Python doesn't make it pretty to get around this issue:

    def min(foo):
        it = iter(foo)
        try:
            m = next(it)
        except StopIteration:
            return None

        for val in it:
            if val < m:
                m = val

        return m


You could switch the order they're compared and due to short-circuiting the second eval would only ever take place once. Or initialize min to the zeroth item in the array.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: