Unique Entry Filter Python Script

This script prompts the user to enter a comma-separated list of strings, then processes the input by trimming whitespace and converting entries to lowercase for case-insensitive duplicate checking. It finally outputs a comma-separated list of unique entries, preserving the order of their first appearance.

Click to view script…
#!/usr/bin/env python3

def remove_duplicates(input_string):
    # Split the input string by commas and remove any extra spaces
    items = [item.strip() for item in input_string.split(',')]
    unique_items = []
    seen = set()

    for item in items:
        # Convert to lowercase for case-insensitive comparison
        if item.lower() not in seen:
            seen.add(item.lower())
            unique_items.append(item)
    return unique_items

if __name__ == '__main__':
    user_input = input("Enter a comma-separated list of strings: ")
    unique = remove_duplicates(user_input)
    print("Unique entries:", ", ".join(unique))