I have an issue that I do not know how to tackle.
For example: I have a string returning in a function that has multiple sentences separatade by a comma. And some of them are comming repeated:
Like:
"lorem ipsum dolor, lorem ipsum dolor, lorem ipsum dolor"
I need to remove these sentences that are comming repeated but without checking word-by-word, rather sentence by sentence striped by ",". Since there may have other sentences with repeated words that should not be removed.
Input example:
"lorem ipsum dolor, lorem ipsum dolor, lorem mark dol"
Output desired:
"lorem ipsum dolor, lorem mark dol"
>Solution :
This solution is based on the Tim Roberts comment. The only difference is OrderedDict usage in order to preserve sentences order:
from collections import OrderedDict
string = 'lorem ipsum dolor, lorem ipsum dolor, lorem mark dol'
string = ', '.join(OrderedDict.fromkeys(string.split(', ')))
print(string)
Output:
lorem ipsum dolor, lorem mark dol