Skip to content

Remove Duplicate Key

Sourcery refactoring id: remove-duplicate-key


Remove duplicate keys in declaration of sets and dicts


addresses = {*address_list1, *address_list2, *address_list1}


addresses = {*address_list2, *address_list1}


Keys of Sets and Dictionaries must be unique. Hence, repeated keys are redundant and can be removed from the declaration to increase the conciseness and clarity of the code.

For dictionaries that have repeated keys with differing values (i.e. {key1: 'some_value', key1: 'another_value'}), Sourcery will only remove the key-value pairs that would be removed at run time.

Back to top