def sort_dict_last(x):

    """
    Sorts a dictionary, placing properties with values that are also
    dictionaries last. If a dictionary has the !dict flag, it will not
    be placed last with the other dict types
    """

    if not isinstance(x, dict):
        return x
    dicts = {}
    other = {}
    for key, value in x.items():
        if isinstance(value, dict) and '!dict' not in key:
            dicts[key] = value
        else:
            other[key] = value
    other.update(dicts)
    return other