Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99471

Re: list slice and generators

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: list slice and generators
Date 2015-11-25 19:22 +0100
Organization None
Message-ID <mailman.83.1448475774.20593.python-list@python.org> (permalink)
References <5654D8CE.2020105@gmail.com> <n3418c$k41$1@ger.gmane.org> <CALwzidmnKPAY+X7tGxPreBXk2JiFnzVAJQ0q-erkcaR7MRtnvw@mail.gmail.com>

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: list slice and generators Peter Otten <__peter__@web.de> - 2015-11-25 19:22 +0100

csiph-web