Is there a way in Python of making a List unique through functional paradigm ?
Input : [1,2,2,3,3,3,4]
Output: [1,2,3,4]
(In order preserving manner)
I know there are other ways but none is in the functional way.
If you need to just delete adjacent occurrences try this:
reduce(lambda x,y: x+[y] if x==[] or x[-1] != y else x, your_list,[])
If you need to delete all but one ocurrence try this:
reduce(lambda x,y: x+[y] if not y in x else x, your_list,[])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With