Dear List members:
I always have problem in getting ranges: Following is my representation of part of my file. >X1 A G C G >X2 A G >X3 A G >X4 H T I want to print the above contents in the following way: X1 \t A X1 \t G X1 \t C X1 \t G X2 \t A X2 \t G X3 \t A X3 \t G X4 \t H X4 \t H Here is what I do : >>> f1 = open('test','r') >>> da = f1.read().split('\n') >>> dat = da[:-1] >>> dat >>> mpos = [] >>> for i in range(len(dat)): if dat[i].startswith('>'): mpos.append(i) >>> mpos [0, 3, 6, 9] >>> for item in range(len(mpos)): start = mpos[item] enda = item+1 end = mpos[enda]-1 head = dat[start] block = dat[start+1:end] for i in block: print head+'\t'+i >X1A >X2A >X3A Traceback (most recent call last): File "<pyshell#31>", line 4, in <module> end = mpos[enda]-1 IndexError: list index out of range >>> By the time I am looping through last item, I do not have anything to take 1 from and thus end up with that indexerror. Could anyone please help me how to get a good habit of making this work. This is a very wrong and bad habit. thank you for your help in advance. Hs.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor