Dangerous behavior of list(generator)

Tom Machinski tom.machinski at gmail.com
Thu Dec 31 14:42:37 EST 2009


On Thu, Dec 31, 2009 at 1:54 AM, Peter Otten <__peter__ at web.de> wrote:
> Somewhat related in 2.6 there's the next() built-in which accepts a default
> value. You can provide a sentinel and test for that instead of using
> try...except:

Thanks. This can be useful in some of the simpler cases. As you surely
realize, to be perfectly safe, especially when the iterable can
contain any value (including your sentinel), we must use an
out-of-band return value, hence an exception is the only truly safe
solution.

  -- Tom



More information about the Python-list mailing list