def parse_ranges(files_and_ranges):

    operations = []
    for inputname in files_and_ranges:
        if inputname.lower().endswith('.pdf'):
            operations.append({"name": inputname,
                               "pdf": read_pdf(inputname),
                               "pages": []})
        else:
            match = re.match('([0-9]+|end)(?:-([0-9]+|end))?([LRD]?)',
                                inputname)
            if not match:
                raise CommandError('Invalid range: {}'.format(inputname))

            current = operations[-1]
            max_page = current['pdf'].getNumPages()
            # allow "end" as alias for the last page
            replace_end = lambda page: (
                max_page if page.lower() == 'end' else int(page))
            begin = replace_end(match.group(1))
            end = replace_end(match.group(2)) if match.group(2) else begin

            rotate = ROTATIONS.get((match.group(3) or 'u').lower())

            if begin > max_page or end > max_page:
                raise CommandError(
                    "Range {}-{} exceeds maximum page number "
                    "{} of file {}".format(
                        begin, end, max_page, current['name']))

            # negative ranges sort pages backwards
            if begin < end:
                pagerange = range(begin, end + 1)
            else:
                pagerange = range(end, begin + 1)[::-1]

            for p in pagerange:
                current['pages'].append((p, rotate))

    return operations
Compute the singular values of a Matrix
dataset/ETHPy150Open hellerbarde/stapler/staplelib/iohelper.py/parse_ranges--crossover with--dataset/ETHPy150Open sympy/sympy/sympy/matrices/matrices.py/MatrixBase.singular_values