On Wed, Nov 26, 2014 at 5:59 AM, <random832@fastmail.us> wrote:
Out of curiosity, what explicit uses of next are pythonic?

Ones immediately enclosed in try/except StopIteration, e.g.:

  try:
      x = next(it)
      print(x)
  except StopIteration:
      print('nothing')

You could rewrite this particular one as follows:

  for x in it:
      print(x)
      break
  else:
      print('nothing')

But if you have multiple next() calls you might be able to have a single try/except catching StopIteration from all of them, so the first pattern is more general.

--
--Guido van Rossum (python.org/~guido)