---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
unnecessary_dict_index_lookup.py:4:6: PLR1733 [*] Unnecessary lookup of dictionary value by key
  |
3 | def fix_these():
4 |     [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
  |      ^^^^^^^^^^^^^^^^^^ PLR1733
5 |     {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
6 |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  |
  = help: Use existing variable

ℹ Safe fix
1 1 | FRUITS = {"apple": 1, "orange": 10, "berry": 22}
2 2 | 
3 3 | def fix_these():
4   |-    [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
  4 |+    [fruit_count for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
5 5 |     {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
6 6 |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
7 7 | 

unnecessary_dict_index_lookup.py:5:6: PLR1733 [*] Unnecessary lookup of dictionary value by key
  |
3 | def fix_these():
4 |     [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
5 |     {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  |      ^^^^^^^^^^^^^^^^^^ PLR1733
6 |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  |
  = help: Use existing variable

ℹ Safe fix
2 2 | 
3 3 | def fix_these():
4 4 |     [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
5   |-    {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  5 |+    {fruit_count for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
6 6 |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
7 7 | 
8 8 |     for fruit_name, fruit_count in FRUITS.items():

unnecessary_dict_index_lookup.py:6:18: PLR1733 [*] Unnecessary lookup of dictionary value by key
  |
4 |     [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
5 |     {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
6 |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  |                  ^^^^^^^^^^^^^^^^^^ PLR1733
7 |
8 |     for fruit_name, fruit_count in FRUITS.items():
  |
  = help: Use existing variable

ℹ Safe fix
3 3 | def fix_these():
4 4 |     [FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()]  # PLR1733
5 5 |     {FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
6   |-    {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
  6 |+    {fruit_name: fruit_count for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
7 7 | 
8 8 |     for fruit_name, fruit_count in FRUITS.items():
9 9 |         print(FRUITS[fruit_name])  # PLR1733

unnecessary_dict_index_lookup.py:9:15: PLR1733 [*] Unnecessary lookup of dictionary value by key
   |
 8 |     for fruit_name, fruit_count in FRUITS.items():
 9 |         print(FRUITS[fruit_name])  # PLR1733
   |               ^^^^^^^^^^^^^^^^^^ PLR1733
10 |         blah = FRUITS[fruit_name]  # PLR1733
11 |         assert FRUITS[fruit_name] == "pear"  # PLR1733
   |
   = help: Use existing variable

ℹ Safe fix
6  6  |     {fruit_name: FRUITS[fruit_name] for fruit_name, fruit_count in FRUITS.items()}  # PLR1733
7  7  | 
8  8  |     for fruit_name, fruit_count in FRUITS.items():
9     |-        print(FRUITS[fruit_name])  # PLR1733
   9  |+        print(fruit_count)  # PLR1733
10 10 |         blah = FRUITS[fruit_name]  # PLR1733
11 11 |         assert FRUITS[fruit_name] == "pear"  # PLR1733
12 12 | 

unnecessary_dict_index_lookup.py:10:16: PLR1733 [*] Unnecessary lookup of dictionary value by key
   |
 8 |     for fruit_name, fruit_count in FRUITS.items():
 9 |         print(FRUITS[fruit_name])  # PLR1733
10 |         blah = FRUITS[fruit_name]  # PLR1733
   |                ^^^^^^^^^^^^^^^^^^ PLR1733
11 |         assert FRUITS[fruit_name] == "pear"  # PLR1733
   |
   = help: Use existing variable

ℹ Safe fix
7  7  | 
8  8  |     for fruit_name, fruit_count in FRUITS.items():
9  9  |         print(FRUITS[fruit_name])  # PLR1733
10    |-        blah = FRUITS[fruit_name]  # PLR1733
   10 |+        blah = fruit_count  # PLR1733
11 11 |         assert FRUITS[fruit_name] == "pear"  # PLR1733
12 12 | 
13 13 | 

unnecessary_dict_index_lookup.py:11:16: PLR1733 [*] Unnecessary lookup of dictionary value by key
   |
 9 |         print(FRUITS[fruit_name])  # PLR1733
10 |         blah = FRUITS[fruit_name]  # PLR1733
11 |         assert FRUITS[fruit_name] == "pear"  # PLR1733
   |                ^^^^^^^^^^^^^^^^^^ PLR1733
   |
   = help: Use existing variable

ℹ Safe fix
8  8  |     for fruit_name, fruit_count in FRUITS.items():
9  9  |         print(FRUITS[fruit_name])  # PLR1733
10 10 |         blah = FRUITS[fruit_name]  # PLR1733
11    |-        assert FRUITS[fruit_name] == "pear"  # PLR1733
   11 |+        assert fruit_count == "pear"  # PLR1733
12 12 | 
13 13 | 
14 14 | def dont_fix_these():

unnecessary_dict_index_lookup.py:50:51: PLR1733 [*] Unnecessary lookup of dictionary value by key
   |
48 |         if mapped_label in mapped_arrays:
49 |             for i in range(len(array)):
50 |                 mapped_arrays[mapped_label][i] += value_arrays[label][i]  # PLR1733
   |                                                   ^^^^^^^^^^^^^^^^^^^ PLR1733
51 |         else:
52 |             mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(len(array))]  # PLR1733
   |
   = help: Use existing variable

ℹ Safe fix
47 47 |         mapped_label = client_label_map(label)
48 48 |         if mapped_label in mapped_arrays:
49 49 |             for i in range(len(array)):
50    |-                mapped_arrays[mapped_label][i] += value_arrays[label][i]  # PLR1733
   50 |+                mapped_arrays[mapped_label][i] += array[i]  # PLR1733
51 51 |         else:
52 52 |             mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(len(array))]  # PLR1733
53 53 |     return mapped_arrays

unnecessary_dict_index_lookup.py:52:44: PLR1733 [*] Unnecessary lookup of dictionary value by key
   |
50 |                 mapped_arrays[mapped_label][i] += value_arrays[label][i]  # PLR1733
51 |         else:
52 |             mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(len(array))]  # PLR1733
   |                                            ^^^^^^^^^^^^^^^^^^^ PLR1733
53 |     return mapped_arrays
   |
   = help: Use existing variable

ℹ Safe fix
49 49 |             for i in range(len(array)):
50 50 |                 mapped_arrays[mapped_label][i] += value_arrays[label][i]  # PLR1733
51 51 |         else:
52    |-            mapped_arrays[mapped_label] = [value_arrays[label][i] for i in range(len(array))]  # PLR1733
   52 |+            mapped_arrays[mapped_label] = [array[i] for i in range(len(array))]  # PLR1733
53 53 |     return mapped_arrays
