<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_user(user, using='records', interaction=None, part_of_week='allweek', part_of_day='allday'):
 """ Filter records of a User objects by interaction, part of week and day. Parameters user : User a bandicoot User object type : str, default 'records' 'records' or 'recharges' part_of_week : {'allweek', 'weekday', 'weekend'}, default 'allweek' * 'weekend': keep only the weekend records * 'weekday': keep only the weekdays records * 'allweek': use all the records part_of_day : {'allday', 'day', 'night'}, default 'allday' * 'day': keep only the records during the day * 'night': keep only the records during the night * 'allday': use all the records interaction : object The interaction to filter records: * "callandtext", for only callandtext; * a string, to filter for one type; * None, to use all records. """


    if using == 'recharges':
        records = user.recharges
    else:
        records = user.records
        if interaction == 'callandtext':
            records = filter(
                lambda r: r.interaction in ['call', 'text'], records)
        elif interaction is not None:
            records = filter(lambda r: r.interaction == interaction, records)

    if part_of_week == 'weekday':
        records = filter(
            lambda r: r.datetime.isoweekday() not in user.weekend, records)
    elif part_of_week == 'weekend':
        records = filter(
            lambda r: r.datetime.isoweekday() in user.weekend, records)
    elif part_of_week != 'allweek':
        raise KeyError(
            "{} is not a valid value for part_of_week. it should be 'weekday', "
            "'weekend' or 'allweek'.".format(part_of_week))

    if user.night_start < user.night_end:
        night_filter = lambda r: user.night_end > r.datetime.time(
        ) > user.night_start
    else:
        night_filter = lambda r: not(
            user.night_end < r.datetime.time() < user.night_start)

    if part_of_day == 'day':
        records = filter(lambda r: not(night_filter(r)), records)
    elif part_of_day == 'night':
        records = filter(night_filter, records)
    elif part_of_day != 'allday':
        raise KeyError(
            "{} is not a valid value for part_of_day. It should be 'day', 'night' or 'allday'.".format(part_of_day))

    return list(records)