<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_action(self, actor, action, date, type=None, committees=None, legislators=None, **kwargs):
 """ Add an action that was performed on this bill. :param actor: a string representing who performed the action. If the action is associated with one of the chambers this should be 'upper' or 'lower'. Alternatively, this could be the name of a committee, a specific legislator, or an outside actor such as 'Governor'. :param action: a string representing the action performed, e.g. 'Introduced', 'Signed by the Governor', 'Amended' :param date: the date/time this action was performed. :param type: a type classification for this action ;param committees: a committee or list of committees to associate with this action """


        def _cleanup_list(obj, default):
            if not obj:
                obj = default
            elif isinstance(obj, string_types):
                obj = [obj]
            elif not isinstance(obj, list):
                obj = list(obj)
            return obj

        type = _cleanup_list(type, ['other'])
        committees = _cleanup_list(committees, [])
        legislators = _cleanup_list(legislators, [])

        if 'committee' in kwargs:
            raise ValueError("invalid param 'committee' passed to add_action, "
                             "must use committees")

        if isinstance(committees, string_types):
            committees = [committees]

        related_entities = []         # OK, let's work some magic.
        for committee in committees:
            related_entities.append({
                "type": "committee",
                "name": committee
            })

        for legislator in legislators:
            related_entities.append({
                "type": "legislator",
                "name": legislator
            })

        self['actions'].append(dict(actor=actor, action=action,
                                    date=date, type=type,
                                    related_entities=related_entities,
                                    **kwargs))