[Python-ideas] Consider making enumerate a sequence if its argument is a sequence
Chris Barker
chris.barker at noaa.gov
Fri Oct 2 01:13:37 CEST 2015
On Thu, Oct 1, 2015 at 12:37 PM, Steven D'Aprano <steve at pearwood.info>
wrote:
> This makes a difference. Just a few days ago, somebody mis-reported a
> supposed "bug" in all() and any(). For example:
>
> values = (x%5 == 3 for x in range(8))
> print(list(values))
> print(all(values)) # should return False
>
> Obvious error is obvious: having printed out the values from the
> generator expression, values is now exhausted, and all() of the empty
> set is True (vacuous truth). The difference between general iterables
> which may or may not be one-shot iterators, and those which are
> definitely not iterators, is not always just an implementation detail.
they used a generator expression, when they clearly wanted a list
comprehension -- so yes, it matters what they were getting, I don't know
that adding more vocabulary would help prevent people from making that
mistake...
if they had been smart enough to call the list() again, before claiming
there was a bug in all -- it may have explained itself.
-Chris
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151001/8391c129/attachment.html>
More information about the Python-ideas
mailing list