This is actually an extension of this question. The answers of that question did not keep the "order" of the list after removing duplicates. How to remove these duplicates in a list (python)
biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'Live Concert by U2','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'} ]
In this case, the 2nd element should be removed because a previous "u2.com" element already exists. However, the order should be kept.
use set(), then re-sort using the index of the original list.
>>> mylist = ['c','a','a','b','a','b','c'] >>> sorted(set(mylist), key=lambda x: mylist.index(x)) ['c', 'a', 'b']
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