list indexes

Asked

Viewed 73 times

-1

My two initial lists have repeated values: B_I=[Cab, Bou, Bou, RFF, RF1, Rf2, Color] Ba_f=[Bou, Zez1, Zez2, Praca, Sro, Sro, Falag]

I eliminated the repeaters, leaving with: Final=[Cab, Bou, RFF, RF1, Rf2, Cor, Zez1, Zez2, Praca, Sro, Falag]

It needed to be at the end with 2 lists of occurrence indexes in each of the initial lists, such as:

B_i_final=[0,1,1,2,3,4,5] Ba_f_final=[1,6,7,8,9,9,10]

I tried this: No_i=[] for a in range(0,Len(Ba_i)): for b in range(0,Len(Final)): if Ba_i[a]==Final[b]: No_i.append(Final.index(b)) Else: No_i.append() I do not know how to do on Else, that is, in the situation where the index in the initial list differs from the index in the final list I wanted to take the value of the index of that element in the final list.. Someone knows how to do this?

1 answer

0


>>> B_I = ['Cab', 'Bou', 'Bou', 'RFF', 'RF1', 'Rf2', 'Cor']
>>> Ba_F = ['Bou', 'Zez1', 'Zez2', 'Praca', 'Sro', 'Sro', 'Falag']
>>> Final = list(set(B_I+Ba_F))
>>> B_I_final = [Final.index(i) for i in B_I]
>>> Ba_F_final = [Final.index(i) for i in Ba_F] 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.