<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_display_list(pairs, sort_by="key", allow_empty=True):
 """Create a Plone DisplayList from list items :param pairs: list of key, value pairs :param sort_by: Sort the items either by key or value :param allow_empty: Allow to select an empty value :returns: Plone DisplayList """

    dl = DisplayList()

    if isinstance(pairs, basestring):
        pairs = [pairs, pairs]
    for pair in pairs:
        # pairs is a list of lists -> add each pair
        if isinstance(pair, (tuple, list)):
            dl.add(*pair)
        # pairs is just a single pair -> add it and stop
        if isinstance(pair, basestring):
            dl.add(*pairs)
            break

    # add the empty option
    if allow_empty:
        dl.add("", "")

    # sort by key/value
    if sort_by == "key":
        dl = dl.sortedByKey()
    elif sort_by == "value":
        dl = dl.sortedByValue()

    return dl