I have a quite long statement:
if LongClassName.results[variable1][longerVariable2][variable3] == 0:
LongClassName.results[variable1][longerVariable2][variable3] = 42
As one can clearly see, there is quite a lot of repetition in this code (the same expression is used in the conditional and in its body). Is there a way of simplifying it? In C++ I could use references, like this:
auto &ref = LongClassName.results[variable1][longerVariable2][variable3];
if (ref == 0) {
ref = 42;
}
What is the Pythonic way of simplifying this expression?