خرید بک لینک

Vote count: 0

let say I have the following array :

 array([2, 0, 0, 1, 0, 1, 0, 0])

how do I get the indices's where I have occurrence of sequence of values. In this case [0,0]. i.e. I should get back :

[1,2,6,7]

thanks

asked 4 mins ago

1 Answer

Vote count: 0

Here's one way to do it iteratively with a forloop

def find_seq(a_list, val):

    seqs = []
    for i, item in enumerate(a_list[:-1]):
        if item == val and a_list[i + 1] == val:
            #or you could append a tuple: seqs.append((i, i+1))
            seqs.append(i)
            seqs.append(i + 1)
    retu seqs

print(find_seq([2, 0, 0, 1, 0, 1, 0, 0], 0))

answered 7 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 22 فروردين 1395 ساعت: 3:37

صفحه بندی