4 ms·
With the new walrus operator you dont need indents anymore. You can write everything in one line in an array: e.g. y=0 for i in range(10): x=i+1
by fxj 7y ago
With the new walrus operator you dont need indents anymore. You can write everything in one line in an array:
e.g.
y=0
for i in range(10):
x=i+1
y=y+x*2
can be written as:
[y:=0] + [[x:=i+1, y:y+x*2] for i in range(10)]
The square brackets are the new curly brackets.
- joshuamorton 7y agoAs others mentioned, using lambdas this has been possible for ages. There's even a too to auto convert pre walrus code to a single line. It's just that no one does it.
- NotSammyHagar 7y agoThat is evil and wonderful. another reason to love/hate python. I'm working on a project for fun over the holidays and of course I wrote it in python 2.7, and it needs to process unicode so I inflicted double punishment on myself ;-) My work project just happens to use python 2.7, causing pain for everyone.