samedi 7 novembre 2020

Why this code is not working for specific type of data?

def find_even_index(arr):
    for a in arr:
        b = arr.index(a)
        if sum(arr[b+1:]) == sum(arr[:b]):
            return b
    return -1

find_even_index([20,10,30,10,10,15,35])
>>> -1

My code works for all type of data except when it encounters a same digit before or after the number. The index does not change for other 10. Why?

Aucun commentaire:

Enregistrer un commentaire