I will tutor you

  • Bloodshot [he/him,any]
    hexagon
    ·
    edit-2
    4 years ago

    I assume you're using array.index(char), which returns the first index. index also accepts a start argument, so ['a', 'b', 'b', 'a'].index('a', 1) will return 3.

    A bit more natural way to write this is to loop over the search list, and just check for equality, like this:

    def indices(array, search):
        indices = []
        for index, value in enumerate(array):
            if search == value:
                indices.append(index)
    
        return indices
    

    This can be its own function or inline. Above, I use enumerate, which allows you to iterate over both the index and the value.