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

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

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

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

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

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

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

PLR1733 [*] Unnecessary lookup of dictionary value by key
  --> unnecessary_dict_index_lookup.py:52:44
   |
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
   |                                            ^^^^^^^^^^^^^^^^^^^
53 |     return mapped_arrays
   |
help: Use existing variable
   |
51 |         else:
   -             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 |     return mapped_arrays
   |
