Is it possible in Python to run multiple counters in a single for loop as in C/C++?
I would want something like -- for i,j in x,range(0,len(x)): I know Python interprets this differently and why, but how would I run two loop counters concurrently in a single for loop?
解决方案
You want zip in general, which combines two iterators, as @S.Mark says. But in this case enumerate does exactly what you need, which means you don't have to use range directly:
for j, i in enumerate(x):
Note that this gives the index of x first, so I've reversed j, i.