You can convert the array elements directly to a tuple using the tuple
constructor :
for i in range(2):
print fmt % ((i, ) + tuple(A[i]))
Here, +
represents tuple concatenation.
Also, if you're coming from FORTRAN you might not yet know about enumerate
, which can be handy for this type of loop operation :
for i, a in enumerate(A):
print fmt % ((i, ) + tuple(a))
You could combine this with itertools.chain
to flatten the pairs from enumerate :
import itertools
for i, a in enumerate(A):
print fmt % tuple(itertools.chain((i, ), a))
These are all probably overkill for what you're trying to do here, but I just wanted to show a few more ways of doing it.