Work with python 2.7 . Considering the following:
S_names=["A", "B", "C", "D", "E", "F", "G"]
S_values=[1,3,4,2,5,8,10]
other=["Z","W","B","S","A","E","X","T","D","G","L","C","F"]
I need to find in what position of other
are the S_names
elements. To get the list of indexes of S_names
elements in other
, resulting in the Result
:
Result=[4,2,11,8,5,12,9]
I tried working with dictionaries doing the following:
def indicesDeElementoNaLista_s(elementoProcurado, lista):
return [i for (i, elemento) in lista if elemento == elementoProcurado]
def elementosNasPosicoes_s(lista, posicoes):
return [lista[i] for i in posicoes]
carg={}
for elemento in S_names:
posicoes=indicesDeElementoNaLista_s(elemento,other)
elementosCorrespondentes=elementosNasPosicoes_s(S_values,posicoes)
cargas_sub[elemento]=elementosCorrespondentes_s
But I got several errors and I do not understand what's wrong ... How can I get around this?