Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20751
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python.': 0.04; 'implements': 0.05; 'example)': 0.07; 'type,': 0.07; 'python': 0.08; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '[])': 0.16; '[gcc': 0.16; 'subject:() ': 0.16; 'subject:sum': 0.16; 'cc:addr:python-list': 0.16; 'language': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'subject:not': 0.19; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; "doesn't": 0.22; 'appropriate': 0.22; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'specify': 0.24; 'received:209.85.220': 0.25; 'cc:2**0': 0.26; 'message- id:@mail.gmail.com': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'can.': 0.30; 'subject:number': 0.30; '(the': 0.30; 'chris': 0.30; 'thu,': 0.32; 'list': 0.32; 'implement': 0.32; 'initial': 0.32; 'certain': 0.34; 'machine': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'should': 0.38; 'received:209': 0.39; 'type': 0.61; 'header:Received:6': 0.61; 'more': 0.61; 'design': 0.61; '(based': 0.84; '2.7.1': 0.84; '4.2.1': 0.84; 'buck': 0.84; 'received:10.220': 0.84; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84; 'jul': 0.93 |
| Received-SPF | pass (google.com: domain of chris@rebertia.com designates 10.220.151.67 as permitted sender) client-ip=10.220.151.67; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of chris@rebertia.com designates 10.220.151.67 as permitted sender) smtp.mail=chris@rebertia.com; dkim=pass header.i=chris@rebertia.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=ZyHVMhuQjFOF2C2DanLoe83MosdLjva6a7RkUtsZysE=; b=NC12o+a4wfGxx8zIGSyNbuOkYOsAhRKOVEVUdCE7TLdeIIp9ZUwKNYvisOAejRpSZV KNajlnzHRm/rmZAokmtwE6Q9n4v/FwLSVtkrhMeTh7qILAH1FRUishMeXEvBSj23E2PM xoaq2ny2CXT5btrSymI9kYdBabf0k6kScBgyU= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <91c71e41-b98c-46f6-b3af-bed894cf9d92@kh11g2000pbb.googlegroups.com> |
| References | <91c71e41-b98c-46f6-b3af-bed894cf9d92@kh11g2000pbb.googlegroups.com> |
| Date | Thu, 23 Feb 2012 13:32:45 -0800 |
| X-Google-Sender-Auth | KH9sg6o9kIaqchIkZpJ9eClbrVU |
| Subject | Re: sum() requires number, not simply __add__ |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Buck Golemon <buck@yelp.com> |
| Content-Type | text/plain; charset=UTF-8 |
| X-Gm-Message-State | ALoCoQl3Yk4IkUzy/rMV1pfpsLD5QnlpNPBEl6YNn+7FwzxYsLBnK2r0Oxl5MRXtxxKm9RfrUpF8 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.89.1330032768.3037.python-list@python.org> (permalink) |
| Lines | 22 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330032768 news.xs4all.nl 6843 [2001:888:2000:d::a6]:42972 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:20751 |
Show key headers only | View raw
On Thu, Feb 23, 2012 at 1:19 PM, Buck Golemon <buck@yelp.com> wrote: > I feel like the design of sum() is inconsistent with other language > features of python. Often python doesn't require a specific type, only > that the type implement certain methods. > > Given a class that implements __add__ why should sum() not be able to > operate on that class? The time machine strikes again! sum() already can. You just need to specify an appropriate initial value (the empty list in this example) for the accumulator : Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> sum([[1,2],[3,4]], []) [1, 2, 3, 4] Cheers, Chris -- http://rebertia.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sum() requires number, not simply __add__ Buck Golemon <buck@yelp.com> - 2012-02-23 13:19 -0800
Re: sum() requires number, not simply __add__ Buck Golemon <buck@yelp.com> - 2012-02-23 13:23 -0800
Re: sum() requires number, not simply __add__ Arnaud Delobelle <arnodel@gmail.com> - 2012-02-23 21:41 +0000
Re: sum() requires number, not simply __add__ Chris Angelico <rosuav@gmail.com> - 2012-02-24 08:53 +1100
Re: sum() requires number, not simply __add__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-23 23:33 +0000
Re: sum() requires number, not simply __add__ Chris Angelico <rosuav@gmail.com> - 2012-02-24 10:39 +1100
Re: sum() requires number, not simply __add__ Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2012-02-24 12:41 +0100
Re: sum() requires number, not simply __add__ Roy Smith <roy@panix.com> - 2012-02-24 08:23 -0500
Re: sum() requires number, not simply __add__ Terry Reedy <tjreedy@udel.edu> - 2012-02-24 16:58 -0500
Re: sum() requires number, not simply __add__ Arnaud Delobelle <arnodel@gmail.com> - 2012-02-23 21:59 +0000
Re: sum() requires number, not simply __add__ Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-23 15:00 -0700
Re: sum() requires number, not simply __add__ Chris Angelico <rosuav@gmail.com> - 2012-02-24 09:04 +1100
Re: sum() requires number, not simply __add__ Arnaud Delobelle <arnodel@gmail.com> - 2012-02-23 22:09 +0000
Re: sum() requires number, not simply __add__ Arnaud Delobelle <arnodel@gmail.com> - 2012-02-23 21:32 +0000
Re: sum() requires number, not simply __add__ Chris Rebert <clp2@rebertia.com> - 2012-02-23 13:32 -0800
Re: sum() requires number, not simply __add__ Buck Golemon <buck@yelp.com> - 2012-02-23 13:38 -0800
Re: sum() requires number, not simply __add__ Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-23 14:54 -0700
Re: sum() requires number, not simply __add__ Stefan Behnel <stefan_ml@behnel.de> - 2012-02-23 22:42 +0100
Re: sum() requires number, not simply __add__ Duncan Booth <duncan.booth@invalid.invalid> - 2012-02-24 11:40 +0000
Re: sum() requires number, not simply __add__ Peter Otten <__peter__@web.de> - 2012-02-24 09:29 +0100
csiph-web