human
Can you provide a the Python code you requested given the following:
Complete the below
def filter_by_name(pkgs, args):

    ''''Filters the sequence of packages according to user prescriptions
    Args:
    pkgs: sequence of packages
    args: parsed command line arguments
    Returns:
    filtered and sorted list of packages'
    '''
assistant
#Here is the Python code you requested.
    if args.filter:
        res = []
        for f in args.filter:
            if (('*' not in f) and ('?' not in f)):
                r = fnmatch.translate((('*' + f) + '*'))
            else:
                r = fnmatch.translate(f)
            rc = re.compile(r, flags=re.IGNORECASE)
            res.append(rc)
        if args.search_description:
            def match(p, f):
                if f.match(p):
                    return True
                pkg = spack.repo.get(p)
                if pkg.__doc__:
                    return f.match(pkg.__doc__)
                return False
        else:
            def match(p, f):
                return f.match(p)
        pkgs = [p for p in pkgs if any((match(p, f) for f in res))]
    return sorted(pkgs, key=(lambda s: s.lower()))