'Matching word in a string in python
Suppose I have a list in the following format :
tagger = [(1,'T1'),(2,'T2'),(3,'T12'),(4,'T22')]
and my tokenized sentences in the following format :
s = [['Record', 'date','T1','-T12'],['HEENT', 'MMM;', 'No', 'scleral', 'icterus;', 'No','T2','T13','T22' ]]
I want to match each tag that is present in the sentence. my try is :
for _,sent in enumerate(s):
for (i,tag) in tagger :
for j ,word in enumerate(sent) :
if tag in word :
sent[j] = tag
and I get
[['Record', 'date', 'T1', 'T1'],
['HEENT', 'MMM;', 'No', 'scleral', 'icterus;', 'No', 'T2', 'T1', 'T2']]
but I want
[['Record', 'date', 'T1', 'T12'],
['HEENT', 'MMM;', 'No', 'scleral', 'icterus;', 'No', 'T2', 'T13', 'T22']]
Thank you in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
