Reputation: 5235
I have tuple of lists. The lengths of the lists are same each other. For example:
tol = ([1,2,3], [4,5,6])
I'd like to loop all pair of two lists like:
for v1, v2 in some_operation(tol):
print "(%f, %f)" % (v1, v2)
The above code should print (1,4)\n(2,5)\n(3,6)\n
.
One (little dirty) way is use zip
for v1, v2 in zip(tol[0], tol[1]):
print...
Could you show me more simple way?
Upvotes: 0
Views: 50
Reputation: 949
Using Zip would be simple and clean
tol = ([1,2,3], [4,5,6])
for v1, v2 in zip(*tol):
print "(%d, %d)" % (v1, v2)
As you expect the output would be (1,4)\n(2,5)\n(3,6)\n
.
Upvotes: 2