Question

Python 3 codes for loops

In my python script, there are 7 rows (0 to 6) in a list of lists (alignments). The SeqIDs of the first 2 rows, the next 2 rows and the last 3 rows are similar. Now, while appending the rows using the following codes

uniques = [] ap = open(tempparse, ‘w’) for row in range(len(alignments)): ap.write(‘row ‘+str(row)+’\n’)

for compare in range(row+1,len(alignments)):
......
......
.......

the last row (i. e. the last one of the last 3 rows in the list ) is not appended because it does not have any subsequent row to compare, and therefore, the six rows are appended except for the last one.

How can I resolve this issue?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Maybe just try adding additional if statement and if there are no subsequent row to compare just add a default value.

If you wish you could share some of the data that you are running this against so that I could test it as well as it is very hard to just imagine the result without seeing any data.