0
 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]]

        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?

Lauraducky
  • 674
  • 11
  • 25
  • Based on a cursory look, it sounds like the yield keyword would be useful to you. https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do – Joey Harwood Dec 14 '17 at 17:47
  • Thank you. I tried using it. Does not give me the output though. Gives me: – kvc_bioinfo Dec 14 '17 at 18:00
  • That is the expected behavior. You need to make use of the generator object as described in the linked question. You can't just change yield to return have it work. – Joey Harwood Dec 14 '17 at 18:41
  • I am very new to python. I am not able to understand how do I do it. – kvc_bioinfo Dec 14 '17 at 19:17

0 Answers0