4 ms·
I agree that it's a violation of the “one and only one” maxim, but that maxim is a bit hard to take as an absolute. I think the problem is that there are alread
by klodolph 8y ago
I agree that it's a violation of the “one and only one” maxim, but that maxim is a bit hard to take as an absolute. I think the problem is that there are already a lot of ways to write things in Python, the biggest example that comes to mind is list comprehensions.
outputs = [f(x) for x in inputs]
Versus:
outputs = []
for x in inputs:
outputs.append(f(x))
The assignment expression lets you:
outputs = [y for x in inputs
if (y := f(x)) is not None]
I know that more complicated list comprehensions in Python are a bit of a sore point for some people, but I would say that they’re also inherently unpythonic, and I like them.
- legostormtroopr 8y agooutputs = [y for x in inputs if (y := f(x)) is not None] I can't stand this new syntax, y is declared and assigned after the first instance of its use.