Search a sequence for its minimum and stop as soon as the lowest possible value is found

Paul Rubin no.email at nospam.invalid
Sun Jan 8 05:04:30 EST 2017


Paul Rubin <no.email at nospam.invalid> writes:
> seems to work, but is ugly.  Maybe there's something better.

    def minabs2(xs):
        def z():
            for x in xs:
                yield abs(x), x
                if x==0: break
        return min(z())[1]

is the same thing but a little bit nicer.



More information about the Python-list mailing list