human
Solve the following python programming problem given the following code:
@receiver(m2m_changed, sender=CourseUserGroup.users.through)
def _cohort_membership_changed(sender, **kwargs):
assistant
#Here is the Python program you requested.

    """Emits a tracking log event each time cohort membership is modified
    """
    def get_event_iter(user_id_iter, cohort_iter):
        '\n                                Returns    a    dictionary    containing    a    mashup    of    cohort    and    user    information    for    the    given    lists\n                                '
        return ({'cohort_id': cohort.id, 'cohort_name': cohort.name, 'user_id': user_id} for user_id in user_id_iter for cohort in cohort_iter)
    action = kwargs['action']
    instance = kwargs['instance']
    pk_set = kwargs['pk_set']
    reverse = kwargs['reverse']
    if (action == 'post_add'):
        event_name = 'edx.cohort.user_added'
    elif (action in ['post_remove', 'pre_clear']):
        event_name = 'edx.cohort.user_removed'
    else:
        return
    if reverse:
        user_id_iter = [instance.id]
        if (action == 'pre_clear'):
            cohort_iter = instance.course_groups.filter(group_type=CourseUserGroup.COHORT)
        else:
            cohort_iter = CourseUserGroup.objects.filter(pk__in=pk_set, group_type=CourseUserGroup.COHORT)
    else:
        cohort_iter = ([instance] if (instance.group_type == CourseUserGroup.COHORT) else [])
        if (action == 'pre_clear'):
            user_id_iter = (user.id for user in instance.users.all())
        else:
            user_id_iter = pk_set
    for event in get_event_iter(user_id_iter, cohort_iter):
        tracker.emit(event_name, event)