import string
import re


def partial_format(s, data, missing="{{{key}}}"):
    """Return string `s` formatted by `data` allowing a partial format

    Arguments:
        s (str): The string that will be formatted
        data (dict): The dictionary used to format with.

    Example:
        >>> partial_format("{d} {a} {b} {c} {d}", {'b': "and", 'd': "left"})
        'left {a} and {c} left'
    """

    class FormatDict(dict):
        """This supports partial formatting.

        Missing keys are replaced with the return value of __missing__.

        """
        def __missing__(self, key):
            return missing.format(key=key)

    formatter = string.Formatter()
    mapping = FormatDict(**data)
    try:
        f = formatter.vformat(s, (), mapping)
    except Exception:
        r_token = re.compile(r"({.*?})")
        matches = re.findall(r_token, s)
        f = s
        for m in matches:
            try:
                f = re.sub(m, m.format(**data), f)
            except KeyError:
                continue
    return f