Q:

Python: How to remove duplicate values(case insensitive) from a list with same order with default key 'ID' and other keys in title-case

For example:
'L' is a List.
L = ['id', 'Name', 'name', 'Name']
Result: ['ID', Name]
L = ['Name', 'name', 'Status']
Result: ['ID', 'Name', 'Status']
I have tried following code but I want more optmized solution, may be with list comprehension.
field_titles = ['id', 'Name', 'name', 'Name']
# Remove duplicate fields
    key_list = ['ID']
    for field in field_titles:

        title_field = field.title().strip()

        if not title_field == 'Id' and title_field not in key_list:

            key_list.append(title_field)

A:

def transform(L):
    S = set(['id'])
    return ['ID'] + [
            item.title()
            for item in L
            if item.lower() not in S and not S.add(item.lower())]

assert transform(['id', 'Name', 'name', 'Name']) == ['ID', 'Name']
assert transform(['Name', 'name', 'Status']) == ['ID', 'Name', 'Status']

