79236732

Date: 2024-11-29 10:33:45
Score: 1
Natty:
Report link

In Python 3.8 and higher there is a feature for cases like this - assignment expression.

test = {
    'x' : (x_val := 1),  # this can be something complex, 
                         # like function call or whatever
    'y' : x_val + 1,
}

So basically, you assign value of 'x' to some variable and then just use it.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: RisAbd