简体   繁体   中英

Need help printing multiple rows in loop

I have a print statement,

print '0.860\t', model[i+26][16],'\t', 0.1*(float(model[i+26][16])),'\t','35\t I (assume 10% error)'

Briefly, my data file is multiple rows, this specific print command prints a row from a specific value (there are multiple values, each with it's own print command). Now, my data has multiple rows for specific values so the print command (here) just ends up printing the first row it comes across. Obviously, I need every row printed that it may come across.

I'm not that good with python so I have only a limited experience with while and range() commands. I'm finding this tricky because it already has the iterative variable 'i' inside of it, so I don't know how to call the whole row. Thanks.

>>> a=[[1,2,3],[4,5,6],[7,8,9]]
>>> for i in a :
...         print i
... 
 [1, 2, 3]
 [4, 5, 6]
 [7, 8, 9]

To keep a track of index we can use:

for count,i in enumerate(a) :
    ...         print a[count]
    ... 


[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM