[New-bugs-announce] [issue25215] Simple extension to iter(): iter() returns empty generator

Jurjen N.E. Bos report at bugs.python.org
Tue Sep 22 17:08:36 CEST 2015


New submission from Jurjen N.E. Bos:

When looking for a "neat" way to create an empty generator, I saw on stackOverflow that the crowd wasn't sure what was the "least ugly" way to do it.
Proposals where:
def emptyIter(): return; yield
or
def emptyIter(): return iter([])

Then it struck me that a trivial extension to the iter() built-in would be to allow to call it without arguments, thus giving a simple to understand empty iterator, and allowing:
def emptyIter(): return iter()
(And, of course, this function would not need to exist in any reasonable program in that case.)

The implementation would be trivial, I assume.

----------
components: Library (Lib)
messages: 251324
nosy: jneb
priority: normal
severity: normal
status: open
title: Simple extension to iter(): iter() returns empty generator
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25215>
_______________________________________


More information about the New-bugs-announce mailing list