Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-08 Thread Matthew Woodcraft
Raymond Hettinger wrote: >Matthew Woodcraft wrote: >> In CPython, the builtin max() and min() have the property that if there >> are items with equal keys, the first item is returned. From a quick look >> at their source, I think this is true for Jython and IronPython too. >> However, this isn'

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-08 Thread Hrvoje Niksic
On 09/07/2010 11:40 PM, Jeffrey Yasskin wrote: Decimal may actually have this backwards. The idea would be that min(*lst) == sorted(lst)[0], and max(*lst) == sorted(lst)[-1]. Here you mean "is" rather than "==", right? The relations you spelled are guaranteed regardless of stability. (This

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-08 Thread Raymond Hettinger
On Sep 7, 2010, at 12:34 PM, Matthew Woodcraft wrote: > In CPython, the builtin max() and min() have the property that if there > are items with equal keys, the first item is returned. From a quick look > at their source, I think this is true for Jython and IronPython too. > > However, this isn'

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Mark Dickinson
On Tue, Sep 7, 2010 at 11:00 PM, Mark Dickinson wrote: > On Tue, Sep 7, 2010 at 10:51 PM, Mark Dickinson wrote: >> On Tue, Sep 7, 2010 at 10:47 PM, Jeffrey Yasskin wrote: >>> It's ignoring the order of the arguments. It also creates >>> a new Decimal object for the return value, so I can't use i

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Mark Dickinson
On Tue, Sep 7, 2010 at 10:51 PM, Mark Dickinson wrote: > On Tue, Sep 7, 2010 at 10:47 PM, Jeffrey Yasskin wrote: >> It's ignoring the order of the arguments. It also creates >> a new Decimal object for the return value, so I can't use id() to >> check which one of identical elements it returns. >

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Mark Dickinson
On Tue, Sep 7, 2010 at 10:40 PM, Jeffrey Yasskin wrote: > Decimal may actually have this backwards. The idea would be that > min(*lst) == sorted(lst)[0], and max(*lst) == sorted(lst)[-1]. Given a > stable sort, then, max of equivalent elements would return the last > element, and min the first. Y

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Mark Dickinson
On Tue, Sep 7, 2010 at 10:47 PM, Jeffrey Yasskin wrote: > Actually, Decimal isn't doing anything along these lines. At least in > Python 2.6, I get: > Decimal('2').max(Decimal('2.0')) > Decimal('2') Decimal('2.0').max(Decimal('2')) > Decimal('2') Decimal('2.0').min(Decimal('2')) > D

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Jeffrey Yasskin
On Tue, Sep 7, 2010 at 2:40 PM, Jeffrey Yasskin wrote: > On Tue, Sep 7, 2010 at 1:44 PM, Mark Dickinson wrote: >> On Tue, Sep 7, 2010 at 8:34 PM, Matthew Woodcraft >> wrote: >>> In CPython, the builtin max() and min() have the property that if there >>> are items with equal keys, the first item

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Jeffrey Yasskin
On Tue, Sep 7, 2010 at 1:44 PM, Mark Dickinson wrote: > On Tue, Sep 7, 2010 at 8:34 PM, Matthew Woodcraft > wrote: >> In CPython, the builtin max() and min() have the property that if there >> are items with equal keys, the first item is returned. From a quick look >> at their source, I think thi

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Matthew Woodcraft
Mark Dickinson wrote: > Matthew Woodcraft wrote: >> In CPython, the builtin max() and min() have the property that if there >> are items with equal keys, the first item is returned. From a quick look >> at their source, I think this is true for Jython and IronPython too. > It's actually not clear

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Laurens Van Houtven
FWIW: I think Mark is right. I never quite understood why that was, but never cared enough to complain. lvh ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/

Re: [Python-Dev] Behaviour of max() and min() with equal keys

2010-09-07 Thread Mark Dickinson
On Tue, Sep 7, 2010 at 8:34 PM, Matthew Woodcraft wrote: > In CPython, the builtin max() and min() have the property that if there > are items with equal keys, the first item is returned. From a quick look > at their source, I think this is true for Jython and IronPython too. It's actually not cl