def collapseStrings(results):
 copy = []
 begun = None
 listsList = [isinstance(s, list) for s in results]
 pred = (lambda e: isinstance(e, tuple))
 tran = {0: (lambda e: splitQuoted(''.join(e))), 1: (lambda e: [''.join([i[0] for i in e])])}
 for (i, c, isList) in zip(list(range(len(results))), results, listsList):
  if isList:
   if (begun is not None):
    copy.extend(splitOn(results[begun:i], pred, tran))
    begun = None
   copy.append(collapseStrings(c))
  elif (begun is None):
   begun = i
 if (begun is not None):
  copy.extend(splitOn(results[begun:], pred, tran))
 return copy

def collapseStrings ( results ) : copy = [ ] begun = None listsList = [ isinstance ( s , list ) for s in results ] pred = ( lambda e : isinstance ( e , tuple ) ) tran = { 0 : ( lambda e : splitQuoted ( '' . join ( e ) ) ) , 1 : ( lambda e : [ '' . join ( [ i [ 0 ] for i in e ] ) ] ) } for ( i , c , isList ) in zip ( list ( range ( len ( results ) ) ) , results , listsList ) : if isList : if ( begun is not None ) : copy . extend ( splitOn ( results [ begun : i ] , pred , tran ) ) begun = None copy . append ( collapseStrings ( c ) ) elif ( begun is None ) : begun = i if ( begun is not None ) : copy . extend ( splitOn ( results [ begun : ] , pred , tran ) ) return copy
turns a list of length-one strings and lists into a list of longer strings and lists .