Hello All,
I wrote following python code:
pos = 100
cigar = [(0, 150), (3, 50), (0, 130), (2, 270), (0, 750),(2,50),(3, 70), (0,500)]
result=list()
for i in cigar:
while i[0] == 0:
if i == 3:
break
end = pos + i[1]
item = [i[0], pos, end]
#print item
result.append(item)
pos=end
matches=list()
for i in result:
if i[0]<1:
matches.append([i[1], i[2]])
#print matches
Here I am trying to generate an output which will give me:
[100, 100+150] i.e [100, 250] and so on
[100+150+50, 100+150+50+130+270+750+50]
[100+150+50+130+270+750+50+70, 100+150+50+130+270+750+50+70+500]
So basically starting from the pos which are equal to 100: it should keep adding the second value from each cigar tuple (0, 150) until a cigar tuple come where the first value is 3 (3, 50) and keep doing it until the end of cigar list.
I have used while loop for this. However, there is something wrong with the loop because it does not give the desired output and it never breaks. Could anyone figure out what am I doing wrong here?
Thank you very much in advance.
Well, if you say "So basically starting from the pos which are equal to 100" that makes no sense to me, because I can not see 100 in your data at all. However, talking about your loop..... It is not surprising, that it never breaks: You check for i equals 3. However, i is the elements of "cigar" which are (0,50), (3, 50) .... etc, but NEVER 3 .... just add a print i after "for i in cigar:" and you will see the value of i. It can not be 3, ever.
100 is the "pos" which are the first starting point
Ah sorry, I was too focused on the 'cigar'. Anyway, I hope you understood the point about not reaching the breaking point, as Devon described in more detail below.
What do you get?