from typing import OrderedDict


def filter_log(logdict, event, invert=False):
    """
    Filter a dictionary of log entries (loaded by load_log)
    by the named event, inverting (logical NOT) if the optional
    invert argument is True.
    """
    d = {}
    for id, val in logdict.items():
        if val['event'] == event:
            if invert:
                continue
            else:
                d[id] = val
        else:
            if invert:
                d[id] = val
            else:
                continue
    return OrderedDict(d)