Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99474
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: list slice and generators |
| Date | Wed, 25 Nov 2015 19:26:57 +0100 |
| Organization | None |
| Lines | 23 |
| Message-ID | <mailman.85.1448476211.20593.python-list@python.org> (permalink) |
| References | <5654D8CE.2020105@gmail.com> <n3418c$k41$1@ger.gmane.org> <CALwzidmnKPAY+X7tGxPreBXk2JiFnzVAJQ0q-erkcaR7MRtnvw@mail.gmail.com> <CALwzidnFXZEVt4OS2v59WHM_Pn=RbE4B6cDt1HMR5_KstUuzKA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de uH84uQseAhcyk0T5SHs0cAlaGmNHEIiIuHbTVJhOu+fg== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'exercise': 0.03; 'elif': 0.04; 'metrics': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typeerror:': 0.09; 'wed,': 0.15; 'calculates': 0.16; 'len(b)': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; '"",': 0.22; 'am,': 0.23; '(most': 0.24; 'header :User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints- To:1': 0.26; 'function': 0.28; "skip:' 10": 0.28; 'complain': 0.29; 'that.': 0.30; 'traceback': 0.33; 'file': 0.34; 'that,': 0.34; 'list': 0.34; 'nov': 0.35; 'list,': 0.36; 'skip:i 20': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'list.': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'actually,': 0.84; 'otten': 0.84; 'average': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd95ef.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:99474 |
Show key headers only | View raw
Ian Kelly wrote: > On Wed, Nov 25, 2015 at 10:44 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote: >> On Wed, Nov 25, 2015 at 3:07 AM, Peter Otten <__peter__@web.de> wrote: >>>> elif name in METRICS_AVG: >>> # writing a function that calculates the average without >>> # materialising the list left as an exercise ;) >> >> metrics = itertools.tee(metrics) >> return int(sum(metrics[0]) / len(metrics[1])) > > Actually, don't do that. It does effectively materialize the list, > just not as a list. Not just that, it will also complain >>> a, b = itertools.tee([1,2,3]) >>> sum(a), len(b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'itertools._tee' has no len()
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: list slice and generators Peter Otten <__peter__@web.de> - 2015-11-25 19:26 +0100
csiph-web