Hey all,
I'm having problems with obtaining the range of positions of certain numbers in an array. As an example, I have:
[0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,0]
as my array. I would like Python to tell me which are the range of positions where I will find ONLY zeros.
i.e. it should spit out: [0,2] , [10,12] , [15] as answers to me.
The script I cracked my brains over is:
s = 0
e = 0
prev_char = ''
s_e_list = []
for char in cover_array:
cnt += 1
#print char, cnt
if char == '1' and prev_char != '1':
e = cnt - 1
#add the start and end to a list
s_e = "%d_%d"%(s,e)
print s_e, s, e
s_e_list.append(s_e)
#intialize start to zero
s = 0
e = 0
#print char
elif s == 0 and prev_char == '1':
s = cnt
print s
elif char == '0':
if s == 0:
s = cnt
prev_char = char
print s_e_list
But the results weren't accurate, it seems to fall short of a few positions. Am I doing it wrongly?
All feedback are welcomed =]
Rosary
You should ask general programming questions on stackoverflow.com, not here. Your question is unrelated to bioinformatics.