On Monday 11 July 2005 08:53 pm, Bengt Richter wrote:
On Tue, 12 Jul 2005 10:12:33 +1000, John Machin <sj******@lexicon.net> wrote:Bengt Richter wrote: for x in (x for x in seq if x is not None):
Byzantine ...
Perhaps not if you wanted to enumerate the selected elements, as in
for i, x in enumerate(x for x in seq if x is not None):
Seems like a bug waiting to happen -- wouldn't someone using that
idiom most likely have *meant* something like this:
for i,x in enumerate(seq):
if x is not None:
print "seq[%d] = %s is not None" % (i, repr(x))
?
But of course that's not equivalent. It's hard to imagine a
use case for an enumerated loop when the object being
iterated over is anonymous (will be lost as soon as the loop
exits).
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks
http://www.anansispaceworks.com