Here, PyCharm warns me for using b outside of the while loop because, and I agree, if we don't go through the loop, b
will not be defined.
What is the best practice here, adding # noqa
after b["test"] = 8
, declaring b = {}
before the while loop (but then we are re-declaring it to be b = {}
the first time we go through the loop)? I'd tend to the second solution because it makes the code more readable, but maybe there's a better solution?
Code:
a = 0
while a != 10:
b = {}
a += 1
b[a] = "something"
b["test"] = 8