from typing import OrderedDict


def _order_dict(d):
    """Convert dict to sorted OrderedDict"""
    if isinstance(d, dict):
        d = [(k, v) for k, v in d.items()]
        d = sorted(d, key=lambda x: x[0])
        return OrderedDict(d)
    elif isinstance(d, OrderedDict):
        return d
    else:
        raise Exception('Must be dict or OrderedDict')