Duplicate checker

    0

    0

    Mahendra Kumar

    beginnerDSAlist

    Python program to check for duplicates in a list

    # take list
    my_list = [1, 2, 4, 5, 7, 4, 2, 10, 8, 8, 9]
    # printing original list
    print('List:', my_list)
    # check duplicates using set()
    seen = set()
    duplicate_item = {x for x in my_list if x in seen or (seen.add(x) or False)}
    if duplicate_item:
        print('Yes, the list contains duplicates.')
    else:
        print('No, the list does not contains duplicates.')
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.