<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lookup_expand(self, stmt, names):
 """Find schema nodes under `stmt`, also in used groupings. `names` is a list with qualified names of the schema nodes to look up. All 'uses'/'grouping' pairs between `stmt` and found schema nodes are marked for expansion. """

        if not names: return []
        todo = [stmt]
        while todo:
            pst = todo.pop()
            for sub in pst.substmts:
                if sub.keyword in self.schema_nodes:
                    qname = self.qname(sub)
                    if qname in names:
                        names.remove(qname)
                        par = sub.parent
                        while hasattr(par,"d_ref"): # par must be grouping
                            par.d_ref.d_expand = True
                            par = par.d_ref.parent
                        if not names: return [] # all found
                elif sub.keyword == "uses":
                    g = sub.i_grouping
                    g.d_ref = sub
                    todo.append(g)
        return names