I want to remove those element from list which has repetition more than one it's like set but order should not be change
[4,6,2,6,1,2] should become [4,6,2,1]
I'am looking for any inbuilt method or list comprehension
I want to remove those element from list which has repetition more than one it's like set but order should not be change
[4,6,2,6,1,2] should become [4,6,2,1]
I'am looking for any inbuilt method or list comprehension
This should do it: use lambda
function and remove duplicates using set
. Tested on Python 2.7
mylist = [4,6,2,6,1,2]
reduce(lambda r, v: v in r[1] and r or (r[0].append(v) or r[1].add(v)) or r, mylist, ([], set()))[0]