def formatSelector(lst):
 expr = []
 for (name, sel) in iter(lst):
  if expr:
   expr.append('.')
  expr.append(name)
  if (sel is not None):
   expr.append(('[%s]' % repr(sel)))
 return ''.join(expr)

def formatSelector ( lst ) : expr = [ ] for ( name , sel ) in iter ( lst ) : if expr : expr . append ( '.' ) expr . append ( name ) if ( sel is not None ) : expr . append ( ( '[%s]' % repr ( sel ) ) ) return '' . join ( expr )
takes a list of tuples .