2019-03-16

Python - Distinct list, preserving original elements order

from collections import OrderedDict
from itertools import izip, repeat

original_list = ['a', 'b', 'b', 'c']
unique_list = list(OrderedDict(izip(original_list, repeat(None))))
print unique_list


Credit to: https://stackoverflow.com/questions/479897/how-to-remove-duplicates-from-python-list-and-keep-order

No comments:

Post a Comment