def find_maxima(x):
    """Find local maxima of x.

    Input arguments:
    x -- 1D list of real numbers

    Output:
    idx -- list of indices of the local maxima in x
    """
    maxima= []
    for i, val in enumerate(x):
        if i == 0 and val > x[i+1]:
            maxima.append(i)
        elif i == len(x) -1 and val > x[len(x) -2]:
            maxima.append(i)
        else:
            if val > x[i-1] and val > x[i+1]:
                maxima.append(i)
    return maxima

if __name__ == "__main__":
    idx = find_maxima([1,3,-2,0,2,1])
    print(idx)
