Combining a list of realtime responses with a list of static responses I have written this code that accepts a list of static times and a list of realtime-delayed times.  These are frequently being refreshed and there are times where a train, for example train 23, is scheduled for 2:00PM, so after 2:00PM it leaves the list. 

But if it's delayed, I still want it to be a part of the final list (predictionArray), which is why I have the boolean flag set the way it is. So basically it compares every static response with every realtime response, and if true, it won't append to predictionArray (since all realtime responses are in there already).
Is there a way I could do this maybe without booleans? 

Again, I need realtime responses in the predictionArray to begin with in case there are any realtime trains that have been added that aren't on the returned static schedule.

def coalesceMetraData(staticResponses, realtimeResponses):
    predictionArray = list(realtimeResponses)
    for response in staticResponses:
        responseExists = False
        for responseReal in realtimeResponses:
            if (response['key'] == responseReal['key']):
                responseExists = True
                break
        if (responseExists != True):
            predictionArray.append(response)

    predictionArray = sorted(predictionArray, key=lambda d:d['time'])

    return predictionArray[:5]
You are constructing a list out of realtimeResponses.

You then iterate over each item in staticResponses, and for each static response, you (slowly) look to see if that key is in your list of realtimeResponses.

Right there is your room for improvement: a list is not the professional data structure of choice for testing if an item is in a collection. For that, you want either a set or a dict.

In your case, you have extra data in your realtimeResponses, but you don't use it. So set seems to be the right choice: put your realtimeResponses key values into a set, and then you can just use code like:

    realKeys = {rtr['key'] for rtr in realtimeResponses}

    for response in staticResponses:
        if response['key'] in realKeys:
            predictionArray.append(response)


Of course, once you have a for and an if in a tight loop, you can replace it with a list comprehension:

predictionArray += [resp for resp in staticResponses if resp['key'] in realKeys]