def add_uids(doctree, condition):
 for node in doctree.traverse(condition):
  node.uid = uuid4().hex
  (yield node)

def add_uids ( doctree , condition ) : for node in doctree . traverse ( condition ) : node . uid = uuid4 ( ) . hex ( yield node )
add a unique id to every node in the doctree which matches the condition and yield the nodes .