4 ms·
The best I could come up with involved some repetition, because of the double-comprehension boilerplate found_nodes = (node.find(SOME_XPATH) for node in tree
by eesmith 8y ago
The best I could come up with involved some repetition, because of the double-comprehension boilerplate
found_nodes = (node.find(SOME_XPATH) for node in tree)
[found_node.get("value") for found_node in found_nodes
if found_node is not None]
or as a one-liner:
[found_node.get("value") for found_node in (
node.find(SOME_XPATH) for node in tree) if found_node is not None]
It's 15 characters longer than your := version, at 110 characters instead of 95.