B
Bram Stolk
Hi there,
If you have a list of elements, you can sort it with an alternative
comparator (default is __lt__())
This is done as:
Lovely stuff, is it not?
Now my question:
What if I need only a max, or min value, and not a complete sort,
but I do want to have a custom compare func.
What could I do?
min() and max() built-ins cannot take a compare func.
Thanks,
Bram
--
------------------------------------------------------------------------------
Bram Stolk, VR Engineer.
SARA Academic Computing Services Amsterdam, PO Box 94613, 1090 GP AMSTERDAM
email: (e-mail address removed) Phone +31-20-5923059 Fax +31-20-6683167
"For the costs of subsidized agriculture in the EU, we can have all 56 million
European cows fly around the world. First Class." - J. Norberg
------------------------------------------------------------------------------
If you have a list of elements, you can sort it with an alternative
comparator (default is __lt__())
This is done as:
[1, -4, 5, -9, 9]l=[5,-4,1,9,-9]
l.sort()
l [-9, -4, 1, 5, 9]
l.sort(lambda x,y: abs(x)-abs(y))
l
Lovely stuff, is it not?
Now my question:
What if I need only a max, or min value, and not a complete sort,
but I do want to have a custom compare func.
What could I do?
min() and max() built-ins cannot take a compare func.
Thanks,
Bram
--
------------------------------------------------------------------------------
Bram Stolk, VR Engineer.
SARA Academic Computing Services Amsterdam, PO Box 94613, 1090 GP AMSTERDAM
email: (e-mail address removed) Phone +31-20-5923059 Fax +31-20-6683167
"For the costs of subsidized agriculture in the EU, we can have all 56 million
European cows fly around the world. First Class." - J. Norberg
------------------------------------------------------------------------------