<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def group_multiecho(bold_sess):
 """ Multiplexes multi-echo EPIs into arrays. Dual-echo is a special case of multi-echo, which is treated as single-echo data. ['sub-01_task-rest_echo-1_run-01_bold.nii.gz', 'sub-01_task-rest_echo-2_run-01_bold.nii.gz', ['sub-01_task-rest_echo-1_run-02_bold.nii.gz', 'sub-01_task-rest_echo-2_run-02_bold.nii.gz', 'sub-01_task-rest_echo-3_run-02_bold.nii.gz'], 'sub-01_task-rest_run-03_bold.nii.gz'] [['sub-01_task-rest_echo-1_run-01_bold.nii.gz', 'sub-01_task-rest_echo-2_run-01_bold.nii.gz', 'sub-01_task-rest_echo-3_run-01_bold.nii.gz'], ['sub-01_task-rest_echo-1_run-02_bold.nii.gz', 'sub-01_task-rest_echo-2_run-02_bold.nii.gz', 'sub-01_task-rest_echo-3_run-02_bold.nii.gz'], 'sub-01_task-rest_run-03_bold.nii.gz'] [['sub-01_task-rest_echo-1_run-01_bold.nii.gz', 'sub-01_task-rest_echo-2_run-01_bold.nii.gz', 'sub-01_task-rest_echo-3_run-01_bold.nii.gz'], ['sub-01_task-rest_echo-1_run-02_bold.nii.gz', 'sub-01_task-rest_echo-2_run-02_bold.nii.gz', 'sub-01_task-rest_echo-3_run-02_bold.nii.gz'], 'sub-01_task-rest_run-03_bold.nii.gz', 'sub-01_task-beh_echo-1_run-01_bold.nii.gz', 'sub-01_task-beh_echo-2_run-01_bold.nii.gz', ['sub-01_task-beh_echo-1_run-02_bold.nii.gz', 'sub-01_task-beh_echo-2_run-02_bold.nii.gz', 'sub-01_task-beh_echo-3_run-02_bold.nii.gz'], 'sub-01_task-beh_run-03_bold.nii.gz'] Some tests from https://neurostars.org/t/fmriprep-from\ -singularity-unboundlocalerror/3299/7 True 6 [False, False, False, False, False, False, True] 3 """

    from itertools import groupby

    def _grp_echos(x):
        if '_echo-' not in x:
            return x
        echo = re.search("_echo-\\d*", x).group(0)
        return x.replace(echo, "_echo-?")

    ses_uids = []
    for _, bold in groupby(bold_sess, key=_grp_echos):
        bold = list(bold)
        # If single- or dual-echo, flatten list; keep list otherwise.
        action = getattr(ses_uids, 'append' if len(bold) > 2 else 'extend')
        action(bold)
    return ses_uids