Skip to content

Files

Latest commit

 

History

History
32 lines (21 loc) · 606 Bytes

duplicate-key.md

File metadata and controls

32 lines (21 loc) · 606 Bytes

Pattern: Duplicate key in dictionary

Issue: -

Description

When dictionary key is redefined, it overwrites the key's value. This may lead to unexpected behavior and hard to detect bugs. Remove any duplicate keys to resolve this issue.

Example of incorrect code:

wrong_dict = {
    'tea': 'for two',
    'two': 'for tea',
    'tea': 'time',

}

Example of correct code:

correct_dict = {
    'tea': 'for two',
    'two': 'for tea',
}

Further Reading