unnecessary-dict-index-lookup / R1733ΒΆ

Message emitted:

Unnecessary dictionary index lookup, use '%s' instead

Description:

Emitted when iterating over the dictionary items (key-item pairs) and accessing the value by index lookup. The value can be accessed directly instead.

Problematic code:

FRUITS = {"apple": 1, "orange": 10, "berry": 22}

for fruit_name, fruit_count in FRUITS.items():
    print(FRUITS[fruit_name])  # [unnecessary-dict-index-lookup]

Correct code:

FRUITS = {"apple": 1, "orange": 10, "berry": 22}

for fruit_name, fruit_count in FRUITS.items():
    print(fruit_count)

Created by the refactoring checker.