怎么给下面这段话去重?

-- 还有 -- 原来 你是水 好好工作 好好工作
庞龙够厉害 直到那一天 主题

最好不要用set()来去重,它会改变原来的词序:

e ='''-- 还有 -- 原来 你是水 好好工作 好好工作
庞龙够厉害 直到那一天 主题'''

e = e.split()

f = []

for i in e:
    if i not in f:
        f.append(i)

print(' '.join(f))

data="""
-- 还有 -- 原来 你是水 好好工作 好好工作
庞龙够厉害 直到那一天 主题
"""
data=data.split()
result=set()
for d in data:
    result.add(d)
print(result)

一段话去重?

a = '-- 还有 -- 原来 你是水 好好工作 好好工作\n庞龙够厉害 直到那一天 主题'
#根据空格分割
b = a.split()
c = list()
for i in b:
    if i not in c:
        c.append(i)



import re

a = '''-- 还有 -- 原来 你是水 好好工作 好好工作
庞龙够厉害 直到那一天 主题'''
b = re.compile(r'\b(\w+)(\s+\1){1,}\b')
c = b.search(a)
a = b.sub(c.group(1),a)
print(a)