Python logoPython/
PTC-W0050

Set declaration has duplicate elementsPTC-W0050

Major severityMajor
Anti-pattern categoryAnti-pattern

A set cannot have two identical values. When a value is repeated in a set literal, only the last occurrence will remain. Thus duplicate values should be either modified or removed. If duplicate elements are needed, that is, multiset, use Counter from collections module.

Not preferred:

my_set = {"one", "two", "one"}

def myfunc(a, b, c):
    my_set = {a, b, a, c}

Preferred:

my_set = {"one", "two", "one"}

def myfunc(a, b, c):
    my_set = {a, b, c}