human
Complete this python program:
def compareEvents(test, actualEvents, expectedEvents):
assistant
#Here is the Python code you requested.

    """Compare two sequences of log events, examining only the the keys which are
    present in both.
    @param test: a test case doing the comparison
    @type test: L{unittest.TestCase}
    @param actualEvents: A list of log events that were emitted by a logger.
    @type actualEvents: L{list} of L{dict}
    @param expectedEvents: A list of log events that were expected by a test.
    @type expected: L{list} of L{dict}
    """
    if (len(actualEvents) != len(expectedEvents)):
        test.assertEqual(actualEvents, expectedEvents)
    allMergedKeys = set()
    for event in expectedEvents:
        allMergedKeys |= set(event.keys())
    def simplify(event):
        copy = event.copy()
        for key in event.keys():
            if (key not in allMergedKeys):
                copy.pop(key)
        return copy
    simplifiedActual = [simplify(event) for event in actualEvents]
    test.assertEqual(simplifiedActual, expectedEvents)