Duncan Booth:
> And for Python 2.5 users only we have the exciting new option of:
> >>> foo = [5, 2, -1, -7, 3, -6, 2, 12]
> >>> min(foo, key=abs)
> -1

Good. This is possibility for older Python:

l = [(rnd()-0.5) * 20 for i in xrange(1000)]
print min( (abs(el), el) for el in l )[1]

Bye,
bearophile

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to