(even the title of this is going to cause flames, I realize)
Python made the deliberate design choice to have the for loop use explicit iterables, with
This is the best I can come up with:
def cfor(first,test,update):
while test(first):
yield first
first = update(first)
def example(blah):
print "do some stuff"
for i in cfor(0,lambda i:i
I wish python had a syntax for closured expressions.
Edit: Also, note that you only have to define cfor once (as opposed to your complicated_iterator function).