<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_pattrs(pattrs: List['api.PrettyAttribute']) -> str: """Generates repr string given a list of pattrs."""

    output = []
    pattrs.sort(
        key=lambda x: (
            _FORMATTER[x.display_group].display_index,
            x.display_group,
            x.name,
        )
    )
    for display_group, grouped_pattrs in groupby(pattrs, lambda x: x.display_group):
        output.append(
            _FORMATTER[display_group].formatter(display_group, grouped_pattrs)
        )

    return '\n'.join(output)