Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.072 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'none)': 0.07; 'col': 0.16; 'oct': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.215.46': 0.30; 'print': 0.32; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'total': 0.65; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=F1bhmvUmtohwL2CR4Ueq/v5TI5dOjeccmR3WRy7C/Cg=; b=Zc+Lrg6QrWeEkwFmrsh5QY/qNhgElPtS9wk3hh+zyHCLaPBNySt32yieENSb81m1np h2fU5MxBRqk2AZ5w7CW5ZFErQ45TeoCm9I7ksNyid/9DZE8iYmliH/FbQJobE/aUgFKe vavMnqPij3lp7vjimC308czLOuUgH1ly7cQkMziOuO7DxIVo37XTcQnQqk6ppGmQ6MT/ EwY2CVzcnQcaB282xXmsqL7AAumdoLiHVXaBzPVSRL/SyyFrT5wK+rxIjVxnOqEstECD iqlYaHStAtW+ORn6YFgvJAwg9nhnBo7dZ8n0NoGMAJfxDMdTWfB10j6o5F5F7CP9Q005 NewA== MIME-Version: 1.0 In-Reply-To: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> From: Ian Kelly Date: Thu, 4 Oct 2012 15:04:53 -0600 Subject: Re: sum function To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349384724 news.xs4all.nl 6977 [2001:888:2000:d::a6]:37572 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30745 On Thu, Oct 4, 2012 at 2:52 PM, wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > total = 0.0 > r = client.scannerGet(scanner) > while r: > for k in (r[0].columns): > total += float(r[0].columns[k].value) > r = client.scannerGet(scanner) > > print total > > Do you know of better (faster) way to do sum? scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) next_r = itertools.partial(client.scannerGet, scanner) total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues())