On Wed, 21 Dec 2011 21:45:13 -0800, GZ wrote: > Hi, > > I am wondering what would be the best way to return an iterator that has > zero items.
return iter([]) > I just noticed the following two are different: > > def f(): > pass That creates a function that does nothing, and then returns None (because Python doesn't have Pascal procedures or C void function). > def g(): > if 0: yield 0 > pass The pass is redundant. This creates a generator function which, when called, doesn't yield anything, then raises StopIteration. -- Steven -- http://mail.python.org/mailman/listinfo/python-list