[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Index of entity in List with a Condition

I have the following sentence,

"Donald Trump is the president of United States of America". 

I am trying to extract the index 'of', not only for single but also
for its multi-occurance (if they occur), from the list of words of the
string, made by simply splitting the sentence.
 index1=[index for index, value in enumerate(words) if value == "of"],
where words=sentence.split()

I could do this part more or less nicely. 

But I am trying to say if the list of words has the words "United"
and "States" and it has "of " in the sentence then the previous 
word before of is, president. 

I am confused how may I write this, if any one may help it.

Thanking in advance.