def ConditionalElement(node, tag, condition, attr=None):
 sub = partial(SubElement, node, tag)
 if bool(condition):
  if isinstance(attr, str):
   elem = sub({attr: '1'})
  elif isinstance(attr, dict):
   elem = sub(attr)
  else:
   elem = sub()
  return elem

def ConditionalElement ( node , tag , condition , attr = None ) : sub = partial ( SubElement , node , tag ) if bool ( condition ) : if isinstance ( attr , str ) : elem = sub ( { attr : '1' } ) elif isinstance ( attr , dict ) : elem = sub ( attr ) else : elem = sub ( ) return elem
utility function for adding nodes if certain criteria are fulfilled an optional attribute can be passed in which will always be serialised as 1 .