3 ms·
for nested loop you can do for child in node.children or []: for attrib in child.attributes or []: …
by singularity2001 8y ago
for nested loop you can do
for child in node.children or []:
for attrib in child.attributes or []:
…
- Doxin 8y agoThat's generally considered unpythonic though. A more pythonic way to write that is for child in node.children if node.children else []: for attrib in child.attributes if child.attributes else []: ... Which, granted, is a lot more verbose and probably not any more readable but at least it's not abusing the or operator.