PY
py
1
2
3
4
5
6
7
8
9
# Challenge: remove duplicate words from a given string
# VcC 2017
ex="so we started so, we start again the gain, we! never give up up! up;"[::-1]
# o/p:"so we started , start again the gain, ! never give up ! ;"
from re import findall as fnd
from collections import Counter as cnt
for w,n in cnt(fnd("(\w+)\W*",ex)).items():
ex=ex.replace(w,"",n-1)
print(ex[::-1])
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run