Thank you and apologizes for posting again. I tried the code you suggested this doesn't give exactly what I want. I just edited the post with my desired output.
How to command python to continue beyond the loop?
Hello friends,
pos = [10, 100, 1000]
cigar = [[(0, 150), (3, 50), (0, 130), (3, 270), (0, 750),(2,50),(1, 70), (0,500)], [(0, 250), (3, 250), (0, 160), (3, 270)(0,750) ,(0,300)], [(0, 150), (3, 150), (0, 130), (3, 250), (0, 950)]]
def find (cigar, pos):
matches=list()
result=list()
#name=list()
for i in cigar:
if i[0] == 1:
continue
end = pos + i[1]
#print i[1]
item = [i[0], pos, end]
result.append(item)
pos=end
for i in result:
if i[0] < 1:
matches.append([i[1],i[2]])
#matches.append([qname])
return matches
for x, y in zip(cigar, pos):
#print x, y
res = find(x, y)
print res
I have this code which gives me half of my desired output:
[[10, 160], [210, 340], [610, 1360], [1410, 1910]]
[[100, 350], [600, 760], [1030, 1780], [1780, 2080]]
[[1000, 1150], [1300, 1430], [1680, 2630]]
My desired output is:
[[10,160],[210,340],[610,1910]]
[[100,350],[600-760],[1030-2180]]
[[1000,1150], [1300-1430], [1680-2630]]
From the code:
for i in result:
if i[0] < 1:
matches.append([i[1], i[2]])
return matches
I want the appending to break every time it hits i[0] == 3. But at the end of the list if it does not find i[3] I want it to continue appending. How can I give that command to the program? Could someone please help me?
Thank you very much in advance.
I also have this question posted at: StackOverflow
And similar post; Biostars
I have been trying this for long but I am not finding a solution to fix this.
• 2,274 views
•
link
1 answer
In general, don't repost questions in multiple places.
for i in result:
if i[0] == 3:
matches.append([i[1], i[2]])
break
else:
continue
return matches if i[0] == 3:
• 0 views
•
link
• 0 views
•
link
Log in to answer this question.
What you mean "End of the list"? Do you mean, the last element of the list? If yes, grab the last element by result[-1]
cigar = [[(0, 150), (3, 50), (0, 130), (3, 270), (0, 750),(2,50),(1, 70), (0,500)], [(0, 250), (3, 250), (0, 160), (3, 270)(0,750) ,(0,300)], [(0, 150), (3, 150), (0, 130), (3, 250), (0, 950)]]
I mean the end of these lists. If you look at the output of my code and my desired output it shows the difference what I am expecting from the code.