Python: Find a list of words in a text and return its index
问题 I have to process a document in plain text, looking for a word list and returning a text window around each word found. I'm using NLTK. I found posts on Stack Overflow where they use regular expressions for finding words, but without getting their index, just printing them. I don't think use RE is right, cause I have to find specific words. 回答1: This is what you are looking for: You can either use str.index or str.find: Contents of file: Lorem ipsum dolor sit amet, consectetur adipiscing elit