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:22:39 +0100 Organization: None Lines: 26 Message-ID: References: <5654D8CE.2020105@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de s5b+NPMO1DX5Y9m/VAV+jwyT69UF0df2RMirpovNNe/Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'context': 0.05; 'metrics': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'exception': 0.13; 'boolean': 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; 'code.': 0.23; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints-To:1': 0.26; "people's": 0.29; 'raise': 0.29; 'code': 0.30; "i'd": 0.31; 'probably': 0.31; 'problem': 0.33; 'changing': 0.34; 'lists': 0.34; 'could': 0.35; 'comment': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'ever': 0.60; 'your': 0.60; 'limit': 0.65; 'sum': 0.69; 'conclude': 0.84; 'average': 0.93; 'choice.': 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99471 Ian Kelly wrote: >>assert metrics > > metrics is always going to be an itertools.chain object at this > assert, so how could the assertion ever fail? Should an assertion ever fail? >From your reaction I conclude that it was puzzling and a comment like # always true in a boolean context would have been the better choice. The problem I was half-heartedly addressing is that >>> if not metrics: >>> return None "works" for empty lists but not for "empty" iterators. If it were my code I'd probably allow the average calculation to raise an exception and the sum to return 0, but there's always a limit to changing other people's code.