DEV Community

Discussion on: The Controversy Behind The Walrus Operator in Python

Collapse
 
aadibajpai profile image
Aadi Bajpai

Honestly, I'm really happy it's coming. I was a bit apprehensive too initially but ever since then I have started noticing places where the walrus operator would really simplify my code. I don't like writing the double lines personally, I really feel this optimization is nice.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

Do you have any cool examples? I’m actually pretty excited to see how the community uses this operator.

Collapse
 
aadibajpai profile image
Aadi Bajpai

I have yet to port my bigger projects to it but if I write something cool I'll let ya know.

Collapse
 
aadibajpai profile image
Aadi Bajpai

Have a cool example now. Calculating diff b/w subsequent values.

>>> data = [10, 14, 34, 49, 70, 77]
>>> prev = 0; 
>>> [-prev + (prev := x) for x in data]
[10, 4, 20, 15, 21, 7]