0

I have following function:

sorted(
    [
        #...
    ],
    key=lambda x: (
        x.get("order", {}).get("data") is None,
        x.get("order", {}).get("data"),
    ),
)

Can I use assignment := here to store x.get("order", {}).get("data") in variable?

Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192

1 Answers1

1

You can, just make sure to paranthesize the expression correctly:

sorted(
    [
        #...
    ],
    key=lambda x: (
        (y := x.get("order", {}).get("data")) is None,
        y,
    ),
)
L3viathan
  • 26,748
  • 2
  • 58
  • 81