<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def committees_legislators(self, *args, **kwargs):
        '''Return an iterable of committees with all the
        legislators cached for reference in the Committee model.
        So do a "select_related" operation on committee members.
        '''
        committees = list(self.committees(*args, **kwargs))
        legislators = self.legislators({'active': True},
                                       fields=['full_name',
                                               settings.LEVEL_FIELD])
        _legislators = {}

        # This will be a cache of legislator objects used in
        # the committees.html template. Includes ids in each
        # legislator's _all_ids field (if it exists.)
        for obj in legislators:
            if 'all_ids' in obj:
                for _id in obj['_all_ids']:
                    _legislators[_id] = obj
            else:
                _legislators[obj['_id']] = obj
        del legislators
        for com in committees:
            com._legislators = _legislators
        return committees