def strip_locals(data):
    """Returns a dictionary with all keys that begin with local_ removed.

    If data is a dictionary, recurses through cleaning the keys of that as well.
    If data is a list, any dictionaries it contains are cleaned. Any lists it
    contains are recursively handled in the same way.

    """

    if isinstance(data, dict):
        return {key: strip_locals(value) for key, value in data.items()
                if not (isinstance(key, str) and key.startswith('local_'))}
    elif isinstance(data, list):
        data = [strip_locals(item) for item in data]

    return data