---
source: crates/ruff_linter/src/rules/perflint/mod.rs
---
PERF403 Use a dictionary comprehension instead of a for-loop
 --> PERF403.py:5:9
  |
3 |     result = {}
4 |     for idx, name in enumerate(fruit):
5 |         result[idx] = name  # PERF403
  |         ^^^^^^^^^^^^^^^^^^
  |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:13:13
   |
11 |     for idx, name in enumerate(fruit):
12 |         if idx % 2:
13 |             result[idx] = name  # PERF403
   |             ^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:33:13
   |
31 |     for idx, name in enumerate(fruit):
32 |         if idx % 2:
33 |             result[idx] = name  # PERF403
   |             ^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:63:13
   |
61 |     for idx, name in enumerate(fruit):
62 |         if idx % 2:
63 |             result[idx] = name  # PERF403
   |             ^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:78:9
   |
76 |     result = {}
77 |     for name in fruit:
78 |         result[name] = name  # PERF403
   |         ^^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:85:9
   |
83 |     result = {}
84 |     for idx, name in enumerate(fruit):
85 |         result[name] = idx  # PERF403
   |         ^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
  --> PERF403.py:94:9
   |
92 |     result = SneakyDict()
93 |     for idx, name in enumerate(fruit):
94 |         result[name] = idx  # PERF403
   |         ^^^^^^^^^^^^^^^^^^
   |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:106:9
    |
104 |       ):
105 |           # comment 3
106 | /         result[
107 | |             name  # comment 4
108 | |         ] = idx  # PERF403
    | |_______________^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:115:9
    |
113 |     a = 1; result = {}; b = 2
114 |     for idx, name in enumerate(fruit):
115 |         result[name] = idx  # PERF403
    |         ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:122:9
    |
120 |     result = {"kiwi": 3}
121 |     for idx, name in enumerate(fruit):
122 |         result[name] = idx  # PERF403
    |         ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:129:9
    |
127 |     (_, result) = (None, {"kiwi": 3})
128 |     for idx, name in enumerate(fruit):
129 |         result[name] = idx  # PERF403
    |         ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:137:9
    |
135 |     print(len(result))
136 |     for idx, name in enumerate(fruit):
137 |         result[name] = idx  # PERF403
    |         ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:145:13
    |
143 |     for idx, name in enumerate(fruit):
144 |         if last_idx := idx % 3:
145 |             result[name] = idx  # PERF403
    |             ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:153:9
    |
151 |     result = {}
152 |     for idx, name in indices, fruit:
153 |         result[name] = idx  # PERF403
    |         ^^^^^^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:162:13
    |
160 |     for k, v in src:
161 |         if True if True else False:
162 |             dst[k] = v
    |             ^^^^^^^^^^
163 |
164 |     for k, v in src:
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:166:13
    |
164 |     for k, v in src:
165 |         if lambda: 0:
166 |             dst[k] = v
    |             ^^^^^^^^^^
167 |
168 | # https://github.com/astral-sh/ruff/issues/18859
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:172:9
    |
170 |     v = {}
171 |     for o,(x,)in():
172 |         v[x,]=o
    |         ^^^^^^^
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:200:9
    |
198 |     v = {}
199 |     for o, (x,) in ["ox"]:
200 |         v[x,] = o
    |         ^^^^^^^^^
201 |     return v
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:207:9
    |
205 |     v = {}
206 |     for (o, p), x in [("op", "x")]:
207 |         v[x] = o, p
    |         ^^^^^^^^^^^
208 |     return v
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:214:9
    |
212 |     v = {}
213 |     for o, (x,) in ["ox"]:
214 |         v[(x,)] = o
    |         ^^^^^^^^^^^
215 |     return v
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:225:13
    |
223 |             # comment
224 |         ):
225 |             result[k] = k
    |             ^^^^^^^^^^^^^
226 |
227 | def f():
    |
help: Replace for loop with dict comprehension

PERF403 Use a dictionary comprehension instead of a for-loop
   --> PERF403.py:233:9
    |
231 |         k  # comment
232 |     ) in ["a", "b", "c"]:
233 |         result[k] = k
    |         ^^^^^^^^^^^^^
    |
help: Replace for loop with dict comprehension
