how to find all the index of an element in a list Python
Question: If I have a list

    
    
    a=[1,0,0,1,0,1,1,1,0,1,0,0]
    

I want to find the index of 0 and 1 respectively, say in this case,

    
    
    index_0 = [1,2,4,8,10,11]
    index_1 = [0,3,5,6,7,9]
    

is there an efficient way to do this?


Answer: 
    index_0 = [i for i, v in enumerate(a) if v == 0]
    index_1 = [i for i, v in enumerate(a) if v == 1]
    

Or with numpy:

    
    
    import numpy as np
    a = np.array(a)
    index_0 = np.where(a == 0)[0]
    index_1 = np.where(a == 1)[0]
    

