<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rst_dict_table(dict_, key_format=str, val_format=str, header=None, sort=True):
 """Returns an RST-formatted table of keys and values from a `dict` Parameters dict_ : dict data to display in table key_format : callable callable function with which to format keys val_format : callable callable function with which to format values header : None, tuple of str a 2-tuple of header for the two columns, or `None` to exclude a header line (default) sort : bool, optional Sort the dictionary keys alphabetically when writing the table. Examples -------- ==== ====== key1 value1 key2 value2 ==== ====== ======== =============== Key Value ======== =============== ``key1`` :class:`value1` ``key2`` :class:`value2` ======== =============== """

    keys, values = zip(*dict_.items())

    # apply formatting
    keys = map(key_format, keys)
    values = map(val_format, values)

    # work out longest elements in each column
    nckey = max(map(len, keys))
    ncval = max(map(len, values))
    if header:
        khead, vhead = header
        nckey = max(nckey, len(khead))
        ncval = max(ncval, len(vhead))

    # build table header line
    divider = "{}  {}".format('='*nckey, '='*ncval)

    def row(key, val):
        fmt = '{{0:{0}s}}  {{1}}'.format(nckey, ncval)
        return fmt.format(key, val)

    # build table of lines
    lines = [divider]
    if header:
        lines.extend((row(*header), divider))
    params = zip(keys, values)
    if sort:
        params = sorted(params)
    for key, val in params:
        fmt = '{{0:{0}s}}  {{1}}'.format(nckey, ncval)
        lines.append(fmt.format(key, val))
    lines.append(divider)

    return '\n'.join(lines)