def group_ordered(list_in):
    result = OrderedDict()
for value in list_in:
    result.setdefault(value, []).append(value)
return [v for group in list(result.values()) for v in group]
Group list-items by order of appearance in unsorted list