<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def insert_group(node, target):
 """Insert node into in target tree, in appropriate group. Uses group and lang from target function. This assumes the node and target share a structure of a first child that determines the grouping, and a second child that will be accumulated in the group. """

    group = target.sort
    lang = target.lang

    collator = Collator.createInstance(Locale(lang) if lang else Locale())
    for child in target.tree:
        order = collator.compare(group(child) or '', group(node) or '')
        if order == 0:
            for nodechild in node[1:]:
                child.append(nodechild)
            break
        elif order > 0:
            child.addprevious(node)
            break
    else:
        target.tree.append(node)