-5

I want to keep a single sentence in string with many the same sentences. Input:

str1 = 'I want to do this to help her to get the job done I want to do this to help her to get the job done'

Expected output:

str2 = 'I want to do this to help her to get the job done'

Not missing some "to". Thanks.

Ochimot
  • 13
  • 6

1 Answers1

1
out = []
for word in str1.split():
    if word not in out:
        out.append(word)

res = " ".join(out)

Matteo Zanoni
  • 3,429
  • 9
  • 27
  • this code have a problem. example – Ochimot May 30 '21 at 04:00
  • this code have a problem. example input ```str1 = ' I want to do this to help her to get the job done' but output just I want to do this to help her to get the job done``` and output ```str2='I want to do this help her get the job done'``` it missing some "to" – Ochimot May 30 '21 at 04:06
  • If you want to support this behaviour then you would need to define your problem better. What do you consider a sentence? (you have to give a rigorous algorithmic answer that does not rely on semantics) – Matteo Zanoni May 31 '21 at 19:22