I want to step the loop iterator explicitly inside the loop. Is there a 'nicer' way to do this than:
idx = iter(range(0, 10))
for i in idx:
print i
if i == 5:
print "consuming %i in step %i" % (next(idx), i)
Edit: I wander if there is a way to get access to the loop-iterator other than defining it explicitly as in my example.
Thanks!
next(idx)? Isn't it explicit and nice enough?idxisn't already an iterator (eg. a list). It's also very uncommon practice to take thenextof an iterator while you're iterating over it. I'd strongly recommend against it.for i in range(0, 10)- but then I don't get access to the iterator-object...