Here you need to specify an ordered and manually filter the list:
from collections import OrderedDict d = OrderedDict() new_list = [] a_list = [1,3,2,3,2,1,3,2,3,1] for i in a_list: if i not in new_list: new_list.append(i) for i, a in enumerate(new_list): if a != "<": d[i] = a
Output:
OrderedDict([(0, 1), (1, 3), (2, 2)])
If the original order is not important:
final_d = {i:a for i, a in enumerate(set(a_list)) if a != "<"}
source share