Re:PEP 572: Python assignment expressions has been accepted
by williamdclt on Tuesday July 03, 2018 @04:20PM
(#17453332)
I vastly prefer the second one, as I would expect to see it written something like this:
tree
.map(node => node.find(SOME_XPATH))
.filter(Boolean)
.map(node => node.get("value"))
I don't use Python on a daily basis, but I find that infinitely more readable than the comprehension version (plus, it's a syntax used in several major languages)
Re:PEP 572: Python assignment expressions has been accepted
by lukeschlather on Tuesday July 03, 2018 @05:40PM
(#17453797)
In fairness, the Python also should be broken up. It should be:
[
found_node.get("value")
for node in tree
if (found_node := node.find(SOME_XPATH)) is not None
]
I think I also prefer Ruby/Javascript style comprehensions, but it's worth comparing well formatted code.
tree.map(node => node.find(SOME_XPATH)).filter(Boolean).map(node => node.get("value"))
I can deal with either language at this level of complexity. Anything more complicated needs more LoC in either language.