Following example:
JavaScript
x
2
1
string1 = "calvin klein design dress calvin klein"
2
How can I remove the second two duplicates "calvin"
and "klein"
?
The result should look like
JavaScript
1
2
1
string2 = "calvin klein design dress"
2
only the second duplicates should be removed and the sequence of the words should not be changed!
Advertisement
Answer
JavaScript
1
8
1
def unique_list(l):
2
ulist = []
3
[ulist.append(x) for x in l if x not in ulist]
4
return ulist
5
6
a="calvin klein design dress calvin klein"
7
a=' '.join(unique_list(a.split()))
8