<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_groups(orientations, *groups, **kwargs):
 """ Create groups of an orientation measurement dataset """

    grouped = []
    # Copy all datasets to be safe (this could be bad for
    # memory usage, so can be disabled).
    if kwargs.pop('copy', True):
        orientations = [copy(o) for o in orientations]

    for o in orientations:
        # Get rid of and recreate group membership
        o.member_of = None
        try:
            grouped += o.members
            for a in o.members:
                a.member_of = o
        except AttributeError:
            pass

    def find(uid):
        try:
            val = next(x for x in orientations if x.hash == uid)
            if val in grouped:
                raise GroupedPlaneError("{} is already in a group."
                                           .format(val.hash))
            return val
        except StopIteration:
            raise KeyError("No measurement of with hash {} found"
                           .format(uid))

    for uid_list in groups:
        vals = [find(uid) for uid in uid_list]
        o = GroupedOrientation(*vals, **kwargs)
        orientations.append(o)

    return orientations