I have 2 list below
Token_Sentence=[['This','is','a','book'],['This','is','a','cat'],['Those','are','two','books']]
Mapping=[['This',1],['is',2],['a',3],['book',4],['cat',5],['Those',6],['are',7],['two',8],['books',9]]
And I want to map Token_Sentence (convert text to index number) like this
[[1,2,3,4],[1,2,3,5],[6,7,8,9]]
and here is my code
for a in range(len(Token_Sentence)):
for b in range(len(Token_Sentence[a])):
for c in range(len(Mapping)):
if Token_Sentence[a][b]==Mapping[c][0]:
Token_Sentence[a][b]=Mapping[c][1]
But the Problem is it's take a very long time to run (my real data list is pretty large).
Is there are other ways to achieve my goal that faster and simpler than I did?