Here's a question about how to print out words before and after overlapping words.

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

For example, if there's a repeating word like "Bob is American. I know a lot of American people. I love them." I know how to print out the first American word that appears when you type in "American 2", but now I know a little bit

How to output the front and back words of all overlapping words as shown in

It's impossible to solve the problem of printing within a sentence unit with a word like this. (I want to solve it without using nltk.))

It's not enough, but I'm attaching the code I wrote.

n = "Bob is American. I know a lot of American people. I love them" 
for x in n :

    w, num = input ("lowercase letters") and numbers in order with spaces.\n").split()
    num = int(num)

    N = str(num)

    if w not in n:
        print("Not found")

    else:
       for i in N:
       i = int(i)

           if i < 2:
                before_w = n[n.index(w)-1]
                after_w = n[n.index(w)+1]
                b_w = before_w
                a_w = after_w
                result = '{0} / {1} / {2}'.format(b_w, w, a_w)               
                print(result)

            else:
                b_w = n[n.index(w)-i : n.index(w)]
                a_w = n[n.index(w)+1 : n.index(w)+i+1]
                b_w = " ".join(b_w)
                a_w = " ".join(a_w)
                result = '{0} / {1} / {2}'.format(b_words, word, a_words) 
                print(result)

Thank you so much for reading the long question.

python

2022-09-20 15:48

1 Answers


2022-09-20 15:48

If you have any answers or tips


© 2022 pinfo. All rights reserved.