DEV Community

Discussion on: The Controversy Behind The Walrus Operator in Python

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]