I would like to ask you how to print out words before and after a specific word.

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

For example, given the sentence "Bob is American. I love him." When I enter "American 2", I want to extract Bob, is/I love with 2 words each.

So far, I've only typed certain words like the code below, so I don't know what to do in the future.

for i in sen:

    word = input ("Enter a word to search for".\n")

    if word in sen:
        result = word
        print("{0} is found".format(word))

        print("Not found")

Thank you for reading my question.


2022-09-20 15:48

1 Answers

2022-09-20 15:48

If you have any answers or tips

© 2022 pinfo. All rights reserved.