版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010870545/article/details/48340993
def uniquify_a_list(ls):
_ = lambda e, ls=[] : None if e in ls else ls.append(e) or ls
return map(_, ls)[0]
def uniquify_a_sorted_list(ls):
# two pointers solution (learn from LeetCode)
# initial position to compare with
j=0
for i, x in enumerate(ls):
if ls[j] != x:
# if x not equals to ls[j], fill x into the next position
j+=1
ls[j] = x
return ls[:j+1] # total j+1 unique elements