I am trying to print a list of indices for elements that are common in both x and y. So in the example below [5,6,8,9,11]
are common in each, so I am wanting my output to be a list of indices for common elements, so in this case, [0,1,3,4,6]
. I tried the below code, but I just get an empty list []
as my output and I dont know where to go from here. Any help will be appreciated.
x= [5,6,7,8,9,10,11,12]
y=[5,6,8,9,11]
y=[]
for i in range(0,len(x)):
if x[i] in y:
y.append(i)
print(y)