import operator


def _compare_dicts(dict1, dict2):
    """Compares two dictionary-like objects and returns a list of tuples
    (*sign*, *key*, *value*). *sign* is '-' if the key is present
    in the first object but not in the second, or the key is present in
    both objects but the values differ. A '+' sign means the opposite.
    A ' ' sign means the key and value are present in both objects.

    Examples::

        >>> compare_dicts({'a': 1, 'b': 2, 'c': 3}, {'b': 2, 'c': 5, 'd': 7})
        [('-', 'a', 1), (' ', 'b', 2), ('-', 'c', 3), ('+', 'c', 5),
         ('+', 'd', 7)]

    """
    keys1 = set(dict1.iterkeys())
    keys2 = set(dict2.iterkeys())
    data = []
    for key in keys1 - keys2:
        data.append(('-', key, dict1[key]))
    for key in keys2 - keys1:
        data.append(('+', key, dict2[key]))
    for key in keys1 & keys2:
        if dict1[key] != dict2[key]:
            data.append(('-', key, dict1[key]))
            data.append(('+', key, dict2[key]))
        else:
            data.append((' ', key, dict1[key]))
    data.sort(key=operator.itemgetter(1))
    return data