4 ms·
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)
by williamdclt 8y ago
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)
- lukeschlather 8y agoIn 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.