David C. Ullrich wrote:
In article <[EMAIL PROTECTED]>,
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
On Fri, 05 Sep 2008 10:22:22 -0500, David C. Ullrich wrote about why max
and min shouldn't accept a default argument:
Think about all the previously elected female or black presidents of the
U
[EMAIL PROTECTED] wrote in news:240454f2-14ee-496a-9078-1abbf80a4e64
@m45g2000hsb.googlegroups.com:
> castironpi:
>> For max and min, why can't you just add your argument to the set
>> itself?
>
> Sometimes that can be done, but in many other situations it's less
> easy, like in the example I hav
I wrote:
Tino Wildenhain wrote:
[...]
sum(['a','b'],'')
: sum() can't sum strings [use
''.join(seq) instead]
Yes which is a bit bad anyway. I don't think hard wiring it is such a
nice idea. You know, walks like a duck, smells like a duck...
If it makes sense to handle things differently
Tino Wildenhain wrote:
Hi,
Luis Zarrabeitia wrote:
Quoting Laszlo Nagy <[EMAIL PROTECTED]>:
...
Even better:
help(sum) shows
===
sum(...)
sum(sequence, start=0) -> value
Returns the sum of a sequence of numbers (NOT strings) plus
the value
of parameter 'start'. When the
Hi,
Luis Zarrabeitia wrote:
Quoting Laszlo Nagy <[EMAIL PROTECTED]>:
...
Even better:
help(sum) shows
===
sum(...)
sum(sequence, start=0) -> value
Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start'. When the sequence is empty, retur
Mensanator wrote:
On Sep 10, 5:36 pm, Terry Reedy <[EMAIL PROTECTED]> wrote:
Sum(s) replaces reduce(lambda x,y: x+y, s, 0), which was thought to be
the most common use of reduce. Sum(s,start) replaces the much less
common reduce(lambda x,y: x+y, s, start).
Reduce(S, s), where S = sum funct
On Sep 10, 5:36 pm, Terry Reedy <[EMAIL PROTECTED]> wrote:
> Mensanator wrote:
> > Are there situations where the sum of an empty
> > list should NOT be 0? Of course there are.
>
> Python Philosopy (my version, for this discussion):
> Make normal things easy; make unusual or difficult things pos
Mensanator wrote:
Are there situations where the sum of an empty
list should NOT be 0? Of course there are.
Python Philosopy (my version, for this discussion):
Make normal things easy; make unusual or difficult things possible.
Application:
Sum([]) == 0 is normal (90+% of cases). Make t
On Sep 7, 3:38 pm, Luis Zarrabeitia <[EMAIL PROTECTED]> wrote:
> Quoting Mensanator <[EMAIL PROTECTED]>:
>
> > Actualy, I already get the behaviour I want. sum([1,None])
> > throws an exception. I don't see why sum([]) doesn't throw
> > an exception also
>
> If you take a "start value" and add to i
Quoting Mensanator <[EMAIL PROTECTED]>:
> Actualy, I already get the behaviour I want. sum([1,None])
> throws an exception. I don't see why sum([]) doesn't throw
> an exception also
If you take a "start value" and add to it every element of a list, should the
process fail if the list is empty?
In article <[EMAIL PROTECTED]>,
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Fri, 05 Sep 2008 10:22:22 -0500, David C. Ullrich wrote about why max
> and min shouldn't accept a default argument:
>
> > Think about all the previously elected female or black presidents of the
> > US. Which one w
In article
<[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> David C. Ullrich:
> > I didn't mention what's below because it doesn't seem
> > likely that saying max([]) = -infinity and
> > min([]) = +infinity is going to make the OP happy...
>
> Well, it sounds cute having Neginfinite and Infinite
castironpi wrote:
On Sep 8, 8:54 am, Boris Borcic <[EMAIL PROTECTED]> wrote:
David C. Ullrich wrote:
(ii) If A is a subset of B then we should have
max(A) <= max(B). This requires that max(empty set)
be something that's smaller than everything else.
So we give up on that.
Er, what about insta
On Sep 8, 8:54 am, Boris Borcic <[EMAIL PROTECTED]> wrote:
> David C. Ullrich wrote:
>
> > (ii) If A is a subset of B then we should have
> > max(A) <= max(B). This requires that max(empty set)
> > be something that's smaller than everything else.
> > So we give up on that.
>
> Er, what about insta
David C. Ullrich wrote:
(ii) If A is a subset of B then we should have
max(A) <= max(B). This requires that max(empty set)
be something that's smaller than everything else.
So we give up on that.
Er, what about instances of variations/elaborations on
class Smaller(object) : __cmp__ = lambda
On Sep 7, 2:17�pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Sun, 7 Sep 2008 10:30:09 -0700 (PDT), Mensanator <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
> > On Sep 6, 11:05?pm, Steven D'Aprano <[EMAIL PROTECTED]
> > cybersource.com.au> wrote:
>
> > > Sheesh. That's
On Sep 7, 1:17�pm, Patrick Maupin <[EMAIL PROTECTED]> wrote:
> On Sep 7, 12:30�pm, Mensanator <[EMAIL PROTECTED]> wrote:
>
> > On Sep 6, 11:05 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > > Sheesh. That's not a problem, because Python is not trying to be a
> > > dialect of SQL.
>
> > And yet, they ad
On Sep 7, 3:13�pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Sun, 07 Sep 2008 14:30:09 -0300, Mensanator <[EMAIL PROTECTED]> escribi�:
>
>
>
> > Actualy, I already get the behaviour I want. sum([1,None])
> > throws an exception. I don't see why sum([]) doesn't throw
> > an exception also
Can we stop this thread now? :)
I think we've all seen what the intended
behavior of sum(), max() and other
similar functions.
cheers
James
On Mon, Sep 8, 2008 at 3:30 AM, Mensanator <[EMAIL PROTECTED]> wrote:
> On Sep 6, 11:05�pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
En Sun, 07 Sep 2008 14:30:09 -0300, Mensanator <[EMAIL PROTECTED]> escribió:
> Actualy, I already get the behaviour I want. sum([1,None])
> throws an exception. I don't see why sum([]) doesn't throw
> an exception also (I understand that behaviour is by design,
> I'm merely pointing out that the d
On Sep 7, 12:30 pm, Mensanator <[EMAIL PROTECTED]> wrote:
> On Sep 6, 11:05 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > Sheesh. That's not a problem, because Python is not trying to be a
> > dialect of SQL.
>
> And yet, they added a Sqlite3 module.
Does that mean that, because there is an 'os' modu
On Sep 6, 11:05�pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 06 Sep 2008 11:22:07 -0700, Mensanator wrote:
>
> [...]
>
> >> They could have decided that sum must take at least two arguments,
> >> because addition requires two arguments and it's meaningless to talk
> >
On Sat, 06 Sep 2008 11:22:07 -0700, Mensanator wrote:
[...]
>> They could have decided that sum must take at least two arguments,
>> because addition requires two arguments and it's meaningless to talk
>> about adding a single number without talking about adding it to
>> something else. But they
"David C. Ullrich" wrote:
>Think about all the previously elected female or black
>presidents of the US. Which one was the tallest?
The current King of France?
- Hendrik
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 5, 10:45�pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 05 Sep 2008 22:20:06 -0400, Manu Hack wrote:
> > On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
> [The rest of this is (mostly) aimed at Mensanator,
Ok, I see where you're coming f
Steven D'Aprano wrote:
> On Sat, 06 Sep 2008 00:33:25 -0400, Manu Hack wrote:
>
>> Actually it's even more natural to state sum([x]) = x, and this way you
>> can never conclude that sum([]) = 0 from there.
>
> But what you can say is that for any list L, sum(L) = sum(L + [0]).
>
> Therefore sum
castironpi wrote:
On Sep 5, 9:20 pm, "Manu Hack" <[EMAIL PROTECTED]> wrote:
On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
On Sep 4, 2:42 pm,
castironpi wrote:
On Sep 5, 9:20 pm, "Manu Hack" <[EMAIL PROTECTED]> wrote:
On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
On Sep 4, 2:42 pm,
On Sat, Sep 6, 2008 at 12:57 AM, castironpi <[EMAIL PROTECTED]> wrote:
> On Sep 5, 9:20 pm, "Manu Hack" <[EMAIL PROTECTED]> wrote:
>> On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
>> > On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
>> >> On Thu, Sep 4, 2008 at 4:2
On Sat, 06 Sep 2008 00:33:25 -0400, Manu Hack wrote:
> Actually it's even more natural to state sum([x]) = x, and this way you
> can never conclude that sum([]) = 0 from there.
But what you can say is that for any list L, sum(L) = sum(L + [0]).
Therefore sum([]) = sum([] +[0]) = 0
--
Steven
On Sep 5, 9:20 pm, "Manu Hack" <[EMAIL PROTECTED]> wrote:
> On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
> > On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
> >> On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
> >> > On Sep 4, 2:42 pm, [EMAIL
On Fri, Sep 5, 2008 at 11:45 PM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Fri, 05 Sep 2008 22:20:06 -0400, Manu Hack wrote:
>
>> On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
> ...
>The reason sum([]) is 0 is that sum( [ x ] ) - x = 0.
It doesn't make s
On Fri, 05 Sep 2008 22:20:06 -0400, Manu Hack wrote:
> On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
...
>>> >The reason sum([]) is 0 is that sum( [ x ] ) - x = 0.
>>>
>>> It doesn't make sense to me. What do you set x to?
>>
>> For all x.
>
> But then how can you conclud
On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote:
> On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
>> On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
>> > On Sep 4, 2:42 pm, [EMAIL PROTECTED] wrote:
>> >> David C. Ullrich:
>>
>> >> > At least in
On Fri, 05 Sep 2008 10:22:22 -0500, David C. Ullrich wrote about why max
and min shouldn't accept a default argument:
> Think about all the previously elected female or black presidents of the
> US. Which one was the tallest?
I know the answer to that one:
All of them!
--
Steven
--
http://
David C. Ullrich wrote:
In article <[EMAIL PROTECTED]>,
Ken Starks <[EMAIL PROTECTED]> wrote:
David C. Ullrich wrote:
I don't see why you feel the two should act the same.
At least in mathematics, the sum of the elements of
the empty set _is_ 0, while the maximum element of the
empty set is
On Sep 5, 1:08 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Thu, 4 Sep 2008 18:09:49 -0700 (PDT), Mensanator <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
> > Too bad. I brought this up because I use Python a lot with
> > database work and rarely for proving theorms
On Sep 5, 3:28 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
> On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
> > On Sep 4, 2:42 pm, [EMAIL PROTECTED] wrote:
> >> David C. Ullrich:
>
> >> > At least in mathematics, the sum of the elements of
> >> > the empty set _is_ 0, while th
David C. Ullrich:
> I didn't mention what's below because it doesn't seem
> likely that saying max([]) = -infinity and
> min([]) = +infinity is going to make the OP happy...
Well, it sounds cute having Neginfinite and Infinite as built-int
objects that can be compared to any other type and are < o
In article
<[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> David C. Ullrich:
> > At least in mathematics, the sum of the elements of
> > the empty set _is_ 0, while the maximum element of the
> > empty set is undefined.
>
> What do you think about my idea of adding that 'default' argument to
>
In article <[EMAIL PROTECTED]>,
Ken Starks <[EMAIL PROTECTED]> wrote:
> David C. Ullrich wrote:
>
> >
> > I don't see why you feel the two should act the same.
> > At least in mathematics, the sum of the elements of
> > the empty set _is_ 0, while the maximum element of the
> > empty set is und
David C. Ullrich wrote:
I don't see why you feel the two should act the same.
At least in mathematics, the sum of the elements of
the empty set _is_ 0, while the maximum element of the
empty set is undefined.
And both for good reason:
(i) If A and B are disjoint sets we certainly want to
ha
David C. Ullrich wrote:
In article
<[EMAIL PROTECTED]>,
Mensanator <[EMAIL PROTECTED]> wrote:
On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
Empty Python lists [] don't know the type of the items it will
contain, so this sounds strange:
sum([])
0
Becaus
On Thu, Sep 4, 2008 at 4:25 PM, castironpi <[EMAIL PROTECTED]> wrote:
> On Sep 4, 2:42 pm, [EMAIL PROTECTED] wrote:
>> David C. Ullrich:
>>
>> > At least in mathematics, the sum of the elements of
>> > the empty set _is_ 0, while the maximum element of the
>> > empty set is undefined.
>>
>> What do
On Sep 4, 12:31 pm, Thomas Bellman <[EMAIL PROTECTED]> wrote:
> Mensanator <[EMAIL PROTECTED]> wrote:
> > Ok, but I don't understand why an empty list is a valid sum
> > whereas a list containing None is not.
>
> You can't conclude the behaviour of the one from the behaviour
> of the other, because
Mensanator <[EMAIL PROTECTED]> wrote:
> Ok, but I don't understand why an empty list is a valid sum
> whereas a list containing None is not.
You can't conclude the behaviour of the one from the behaviour
of the other, because the two situations have nothing at all in
common.
>> As it happens, th
castironpi:
> For max and min, why can't you just add your argument to the set
> itself?
Sometimes that can be done, but in many other situations it's less
easy, like in the example I have shown in my first post:
max((fun(x) for x in iterable if predicate(x)))
There are some ways to add the max
On Sep 4, 2:42 pm, [EMAIL PROTECTED] wrote:
> David C. Ullrich:
>
> > At least in mathematics, the sum of the elements of
> > the empty set _is_ 0, while the maximum element of the
> > empty set is undefined.
>
> What do you think about my idea of adding that 'default' argument to
> the max()/min()
David C. Ullrich:
> At least in mathematics, the sum of the elements of
> the empty set _is_ 0, while the maximum element of the
> empty set is undefined.
What do you think about my idea of adding that 'default' argument to
the max()/min() functions?
Bye,
bearophile
--
http://mail.python.org/mail
On Thu, 4 Sep 2008 10:57:35 -0700 (PDT), Mensanator wrote:
> Why then, doesn't
>
sum([A for A in [None, None, None, None, None, None] if A != None])
> 0
>
> give me an error?
Because "[A for A in [None, None, None, None, None, None] if A != None]"
returns an empty list, and sum([]) doesn't r
On Sep 4, 2:05 am, Thomas Bellman <[EMAIL PROTECTED]> wrote:
> Mensanator <[EMAIL PROTECTED]> wrote:
> > No, but blank cells are 0 as far as Excel is concerned.
> > That behaviour causes nothing but trouble and I am
> > saddened to see Python emulate such nonsense.
>
> Then you should feel glad tha
On Sep 4, 11:13 am, "David C. Ullrich" <[EMAIL PROTECTED]> wrote:
> In article
> <[EMAIL PROTECTED]>,
>
>
>
>
>
> Mensanator <[EMAIL PROTECTED]> wrote:
> > On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > > > Empty Python lists [] don't know the type of
In article
<[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Empty Python lists [] don't know the type of the items it will
> contain, so this sounds strange:
>
> >>> sum([])
> 0
>
> Because that [] may be an empty sequence of someobject:
>
> >>> sum(s for s in ["a", "b"] if len(s) > 2)
> 0
>
In article
<[EMAIL PROTECTED]>,
Mensanator <[EMAIL PROTECTED]> wrote:
> On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> > > Empty Python lists [] don't know the type of the items it will
> > > contain, so this sounds strange:
> >
> > sum([])
> >
> >
Mensanator <[EMAIL PROTECTED]> wrote:
> No, but blank cells are 0 as far as Excel is concerned.
> That behaviour causes nothing but trouble and I am
> saddened to see Python emulate such nonsense.
Then you should feel glad that the Python sum() function *does*
signal an error for the closest equi
On Sep 4, 1:26 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 03 Sep 2008 22:20:43 -0700, Mensanator wrote:
> > On Sep 3, 8:30 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > cybersource.com.au> wrote:
> >> On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
> >> sum(
On Wed, 03 Sep 2008 22:20:43 -0700, Mensanator wrote:
> On Sep 3, 8:30�pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
>> On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
>> sum([])
>> > 0
>>
>> > is a bug, just as it's a bug in Excel to evaluate blank cells as 0.
>>
Mensanator wrote:
No it isn't. Nothing is not 0, check with MS-Access, for instance:
Null + 1 returns Null. Any arithmetic expression involving a
Null evaluates to Null. Adding something to an unknown returns
an unknown, as it should.
It is a logical fallacy to equate unknown with 0.
http://
On Sep 4, 12:20�am, Mensanator <[EMAIL PROTECTED]> wrote:
> On Sep 3, 8:30 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
> cybersource.com.au> wrote:
> > On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
> > sum([])
> > > 0
>
> > > is a bug, just as it's a bug in Excel to evaluate blank cells a
On Sep 3, 8:30�pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
> sum([])
> > 0
>
> > is a bug, just as it's a bug in Excel to evaluate blank cells as 0. It
> > should return None or throw an exception like sum([None,1])
Quoting Laszlo Nagy <[EMAIL PROTECTED]>:
> [EMAIL PROTECTED] wrote:
> > Empty Python lists [] don't know the type of the items it will
> > contain, so this sounds strange:
> >
> >
> sum([])
>
> > 0
> >
> > Because that [] may be an empty sequence of someobject:
> >
>
> Y
On Wed, 03 Sep 2008 16:20:39 -0700, Mensanator wrote:
sum([])
> 0
>
> is a bug, just as it's a bug in Excel to evaluate blank cells as 0. It
> should return None or throw an exception like sum([None,1]) does.
You're wrong, because 99.9% of the time when users leave a blank cell in
Excel, t
On Sep 3, 7:48 am, [EMAIL PROTECTED] wrote:
> Empty Python lists [] don't know the type of the items it will
> contain, so this sounds strange:
>
> >>> sum([])
>
> 0
>
> Because that [] may be an empty sequence of someobject:
>
> >>> sum(s for s in ["a", "b"] if len(s) > 2)
>
> 0
>
> In a staticall
On Sep 3, 2:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Empty Python lists [] don't know the type of the items it will
> > contain, so this sounds strange:
>
> sum([])
>
> > 0
>
> > Because that [] may be an empty sequence of someobject:
>
> You are right in th
Laszlo Nagy:
> I believe that there have been excessive discussions about this
> decision, and the current implementation is very good, if not the best.
I see. But note that my post is mostly about the max()/min()
functions :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-lis
On Sep 3, 8:18 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Empty Python lists [] don't know the type of the items it will
> > contain, so this sounds strange:
>
> sum([])
>
> > 0
>
> > Because that [] may be an empty sequence of someobject:
>
> You are right in th
[EMAIL PROTECTED] wrote:
Empty Python lists [] don't know the type of the items it will
contain, so this sounds strange:
sum([])
0
Because that [] may be an empty sequence of someobject:
You are right in that sum could be used to sum arbitrary objects.
However, in 99.99% of
<[EMAIL PROTECTED]> wrote:
>Empty Python lists [] don't know the type of the items it will
>contain, so this sounds strange:
>
sum([])
>0
>>> help(sum)
sum(...)
sum(sequence, start=0) -> value
>>> sum(range(x) for x in range(5))
Traceback (most recent call last):
File "", line 1, in
68 matches
Mail list logo