<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_problems( problems: List, *, as_df: bool = False ) -> Union[List, DataFrame]: """ Format the given problems list as a DataFrame. Parameters problems : list A four-tuple containing 1. A problem type (string) equal to ``'error'`` or ``'warning'``; ``'error'`` means the GTFS is violated; ``'warning'`` means there is a problem but it is not a GTFS violation 2. A message (string) that describes the problem 3. A GTFS table name, e.g. ``'routes'``, in which the problem occurs 4. A list of rows (integers) of the table's DataFrame where the problem occurs as_df : boolean Returns ------- list or DataFrame Return ``problems`` if not ``as_df``; otherwise return a DataFrame with the problems as rows and the columns ``['type', 'message', 'table', 'rows']``. """

    if as_df:
        problems = pd.DataFrame(
            problems, columns=["type", "message", "table", "rows"]
        ).sort_values(["type", "table"])
    return problems