Python

Python

By DeepSource

Set declaration has duplicate elements PTC-W0050

Anti-pattern
Autofix

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}