Input:
glist = [1,4,2,5,2,2]
Expected output:
[1,4,2,5]
As you can see, I just want to remove the duplicates, the order of elements I want it to be same
Usual way to remove duplicates:
def remove(glist):
result = []
for ele in glist:
if ele not in result:
result.append(ele)
return result
However, this code will create a new list, which is result
.
I just want to remove the duplicates, WITHOUT creating new list/set. Meaning I want return glist
as show below
My python: IDLE 3.3
Thanks guys!!!
Presentation of expected code:
def remove(glist):
'''code'''
return glist